From 5aad51098d4bae73220aa58180cf562bccc4a213 Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Fri, 24 Mar 2023 10:25:52 +0800 Subject: [PATCH] Avoid misalign --- compiler/rustc_session/src/filesearch.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index 2c804f0f0a4..9c8a28a4a7e 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -85,15 +85,20 @@ fn current_dll_path() -> Result { #[cfg(target_os = "aix")] unsafe { let addr = current_dll_path as u64; - let mut buffer = vec![0i8; 4096]; + let mut buffer = vec![std::mem::zeroed::(); 64]; loop { - if libc::loadquery(libc::L_GETINFO, buffer.as_mut_ptr(), buffer.len() as u32) >= 0 { + if libc::loadquery( + libc::L_GETINFO, + buffer.as_mut_ptr() as *mut i8, + (std::mem::size_of::() * buffer.len()) as u32, + ) >= 0 + { break; } else { if std::io::Error::last_os_error().raw_os_error().unwrap() != libc::ENOMEM { return Err("loadquery failed".into()); } - buffer.resize(buffer.len() * 2, 0i8); + buffer.resize(buffer.len() * 2, std::mem::zeroed::()); } } let mut current = buffer.as_mut_ptr() as *mut libc::ld_info;