From 4eaf701cb79cd9255333abad8482e69987f86280 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 6 Sep 2023 21:45:12 -0700 Subject: [PATCH] Address clippy warnings --- native/src/boot/cpio.rs | 2 ++ native/src/boot/patch.rs | 3 +-- native/src/boot/payload.rs | 5 ++--- native/src/boot/sign.rs | 3 ++- native/src/init/logging.rs | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/native/src/boot/cpio.rs b/native/src/boot/cpio.rs index d19ce29e9..3a11f0df6 100644 --- a/native/src/boot/cpio.rs +++ b/native/src/boot/cpio.rs @@ -1,3 +1,5 @@ +#![allow(clippy::useless_conversion)] + use std::collections::BTreeMap; use std::ffi::CStr; use std::fmt::{Display, Formatter, Write as FmtWrite}; diff --git a/native/src/boot/patch.rs b/native/src/boot/patch.rs index 49a5e0b42..cac96e9c4 100644 --- a/native/src/boot/patch.rs +++ b/native/src/boot/patch.rs @@ -86,8 +86,7 @@ pub fn patch_encryption(buf: &mut [u8]) -> usize { } fn hex2byte(hex: &[u8]) -> Vec { - let mut v = Vec::new(); - v.reserve(hex.len() / 2); + let mut v = Vec::with_capacity(hex.len() / 2); for bytes in hex.chunks(2) { if bytes.len() != 2 { break; diff --git a/native/src/boot/payload.rs b/native/src/boot/payload.rs index e10d3044e..7b1a9ba97 100644 --- a/native/src/boot/payload.rs +++ b/native/src/boot/payload.rs @@ -60,8 +60,7 @@ fn do_extract_boot_from_payload( return Err(bad_payload!("manifest signature length is zero")); } - let mut buf = Vec::new(); - buf.resize(manifest_len, 0u8); + let mut buf = vec![0; manifest_len]; let manifest = { 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()) { return Err(bad_payload!("decompression failed")); } - }, + } _ => return Err(bad_payload!("unsupported operation type")), }; } diff --git a/native/src/boot/sign.rs b/native/src/boot/sign.rs index 4766e3f26..3b578af63 100644 --- a/native/src/boot/sign.rs +++ b/native/src/boot/sign.rs @@ -27,6 +27,7 @@ use base::{log_err, LoggedResult, MappedFile, ResultExt, StrErr, Utf8CStr}; use crate::ffi::BootImage; +#[allow(clippy::upper_case_acronyms)] pub enum SHA { SHA1(Sha1), SHA256(Sha256), @@ -319,5 +320,5 @@ pub fn sign_boot_image( }; sig.to_der().log() } - inner(payload, name, cert, key).unwrap_or(Vec::new()) + inner(payload, name, cert, key).unwrap_or_default() } diff --git a/native/src/init/logging.rs b/native/src/init/logging.rs index 5e3f52431..30a38b10e 100644 --- a/native/src/init/logging.rs +++ b/native/src/init/logging.rs @@ -17,7 +17,7 @@ pub fn setup_klog() { unsafe { let mut fd = open(raw_cstr!("/dev/null"), O_RDWR | O_CLOEXEC); 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); fs::remove_file("/null").ok(); } @@ -34,7 +34,7 @@ pub fn setup_klog() { KMSG.set(kmsg).ok(); } else { 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()) .ok(); unlink(raw_cstr!("/kmsg"));