Address clippy warnings

This commit is contained in:
topjohnwu 2023-09-06 21:45:12 -07:00
parent 4fff2aa7d8
commit 4eaf701cb7
5 changed files with 9 additions and 8 deletions

View File

@ -1,3 +1,5 @@
#![allow(clippy::useless_conversion)]
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt::{Display, Formatter, Write as FmtWrite}; use std::fmt::{Display, Formatter, Write as FmtWrite};

View File

@ -86,8 +86,7 @@ pub fn patch_encryption(buf: &mut [u8]) -> usize {
} }
fn hex2byte(hex: &[u8]) -> Vec<u8> { fn hex2byte(hex: &[u8]) -> Vec<u8> {
let mut v = Vec::new(); let mut v = Vec::with_capacity(hex.len() / 2);
v.reserve(hex.len() / 2);
for bytes in hex.chunks(2) { for bytes in hex.chunks(2) {
if bytes.len() != 2 { if bytes.len() != 2 {
break; break;

View File

@ -60,8 +60,7 @@ fn do_extract_boot_from_payload(
return Err(bad_payload!("manifest signature length is zero")); return Err(bad_payload!("manifest signature length is zero"));
} }
let mut buf = Vec::new(); let mut buf = vec![0; manifest_len];
buf.resize(manifest_len, 0u8);
let manifest = { let manifest = {
let manifest = &mut buf[..manifest_len]; let manifest = &mut buf[..manifest_len];
@ -171,7 +170,7 @@ fn do_extract_boot_from_payload(
if !ffi::decompress(data, out_file.as_raw_fd()) { if !ffi::decompress(data, out_file.as_raw_fd()) {
return Err(bad_payload!("decompression failed")); return Err(bad_payload!("decompression failed"));
} }
}, }
_ => return Err(bad_payload!("unsupported operation type")), _ => return Err(bad_payload!("unsupported operation type")),
}; };
} }

View File

@ -27,6 +27,7 @@ use base::{log_err, LoggedResult, MappedFile, ResultExt, StrErr, Utf8CStr};
use crate::ffi::BootImage; use crate::ffi::BootImage;
#[allow(clippy::upper_case_acronyms)]
pub enum SHA { pub enum SHA {
SHA1(Sha1), SHA1(Sha1),
SHA256(Sha256), SHA256(Sha256),
@ -319,5 +320,5 @@ pub fn sign_boot_image(
}; };
sig.to_der().log() sig.to_der().log()
} }
inner(payload, name, cert, key).unwrap_or(Vec::new()) inner(payload, name, cert, key).unwrap_or_default()
} }

View File

@ -17,7 +17,7 @@ pub fn setup_klog() {
unsafe { unsafe {
let mut fd = open(raw_cstr!("/dev/null"), O_RDWR | O_CLOEXEC); let mut fd = open(raw_cstr!("/dev/null"), O_RDWR | O_CLOEXEC);
if fd < 0 { if fd < 0 {
mknod(raw_cstr!("/null"), S_IFCHR | 0666, makedev(1, 3)); mknod(raw_cstr!("/null"), S_IFCHR | 0o666, makedev(1, 3));
fd = open(raw_cstr!("/null"), O_RDWR | O_CLOEXEC); fd = open(raw_cstr!("/null"), O_RDWR | O_CLOEXEC);
fs::remove_file("/null").ok(); fs::remove_file("/null").ok();
} }
@ -34,7 +34,7 @@ pub fn setup_klog() {
KMSG.set(kmsg).ok(); KMSG.set(kmsg).ok();
} else { } else {
unsafe { unsafe {
mknod(raw_cstr!("/kmsg"), S_IFCHR | 0666, makedev(1, 11)); mknod(raw_cstr!("/kmsg"), S_IFCHR | 0o666, makedev(1, 11));
KMSG.set(File::options().write(true).open("/kmsg").unwrap()) KMSG.set(File::options().write(true).open("/kmsg").unwrap())
.ok(); .ok();
unlink(raw_cstr!("/kmsg")); unlink(raw_cstr!("/kmsg"));