From a8eef005952103cdeff10c377191af49d95de86e Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Fri, 9 Sep 2022 00:11:44 +0000 Subject: [PATCH 1/2] clippy: Fix latest nightly lints Signed-off-by: Dave Tucker --- xtask/src/build_ebpf.rs | 2 +- xtask/src/docs/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xtask/src/build_ebpf.rs b/xtask/src/build_ebpf.rs index 1ba16b2d..9b9e56d5 100644 --- a/xtask/src/build_ebpf.rs +++ b/xtask/src/build_ebpf.rs @@ -81,7 +81,7 @@ fn build_rust_ebpf(opts: &Options) -> anyhow::Result<()> { fn get_libbpf_headers>(libbpf_dir: P, include_path: P) -> anyhow::Result<()> { let dir = include_path.as_ref(); - fs::create_dir_all(&dir)?; + fs::create_dir_all(dir)?; let status = Command::new("make") .current_dir(libbpf_dir.as_ref().join("src")) .arg(format!("INCLUDEDIR={}", dir.as_os_str().to_string_lossy())) diff --git a/xtask/src/docs/mod.rs b/xtask/src/docs/mod.rs index 8705cae7..dfdd827f 100644 --- a/xtask/src/docs/mod.rs +++ b/xtask/src/docs/mod.rs @@ -55,7 +55,7 @@ pub fn docs() -> Result<(), anyhow::Error> { fn build_docs(working_dir: &PathBuf, abs_header_path: &Path) -> Result<(), anyhow::Error> { let replace = Command::new("sed") - .current_dir(&working_dir) + .current_dir(working_dir) .args(vec!["-i.bak", "s/crabby.svg/crabby_dev.svg/", "src/lib.rs"]) .status() .expect("failed to replace logo"); @@ -64,7 +64,7 @@ fn build_docs(working_dir: &PathBuf, abs_header_path: &Path) -> Result<(), anyho let args = vec!["+nightly", "doc", "--no-deps", "--all-features"]; let status = Command::new("cargo") - .current_dir(&working_dir) + .current_dir(working_dir) .env( "RUSTDOCFLAGS", format!("--html-in-header {}", abs_header_path.to_str().unwrap()), From b2924a3a264732e6de6898a1f03d7cb22d1d0dc5 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Fri, 9 Sep 2022 00:45:29 +0000 Subject: [PATCH 2/2] aya-log: Make miri happy Miri took issue about using slice::from_raw_parts without checking for alignment. Instead, we can simply convert to a [u8;16] into a [u16;8] by iterating in chunks of 2 and bitshifting (remembering that these arrays are in network-endian order). Signed-off-by: Dave Tucker --- aya-log/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/aya-log/src/lib.rs b/aya-log/src/lib.rs index 5786955c..b56c16e6 100644 --- a/aya-log/src/lib.rs +++ b/aya-log/src/lib.rs @@ -53,7 +53,7 @@ use std::{ fmt::{LowerHex, UpperHex}, io, mem, net::{Ipv4Addr, Ipv6Addr}, - ptr, slice, str, + ptr, str, sync::Arc, }; @@ -412,10 +412,11 @@ fn log_buf(mut buf: &[u8], logger: &dyn Log) -> Result<(), ()> { full_log_msg.push_str(&value.format(last_hint.take())?); } Argument::ArrU16Len8 => { - let ptr = attr.value.as_ptr().cast::(); - let slice = unsafe { slice::from_raw_parts(ptr, 8) }; + let data: [u8; 16] = attr.value.try_into().map_err(|_| ())?; let mut value: [u16; 8] = Default::default(); - value.copy_from_slice(slice); + for (i, s) in data.chunks_exact(2).enumerate() { + value[i] = ((s[1] as u16) << 8) | s[0] as u16; + } full_log_msg.push_str(&value.format(last_hint.take())?); } Argument::Str => match str::from_utf8(attr.value) {