From c7b988c8254e21b43dc0fa9056128cd02dc3b5e6 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Mon, 15 Aug 2022 09:10:50 +0100 Subject: [PATCH] uutils: Remove use of mem::uninitialized (#3808) --- src/uu/id/src/id.rs | 10 +++++++--- src/uu/sync/src/sync.rs | 7 ++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index fcb2ec19e..93be02bf0 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -543,14 +543,18 @@ fn auditid() {} #[cfg(not(any(target_os = "linux", target_os = "android")))] fn auditid() { - #[allow(deprecated)] - let mut auditinfo: audit::c_auditinfo_addr_t = unsafe { std::mem::uninitialized() }; - let address = &mut auditinfo as *mut audit::c_auditinfo_addr_t; + use std::mem::MaybeUninit; + + let mut auditinfo: MaybeUninit = MaybeUninit::uninit(); + let address = auditinfo.as_mut_ptr(); if unsafe { audit::getaudit(address) } < 0 { println!("couldn't retrieve information"); return; } + // SAFETY: getaudit wrote a valid struct to auditinfo + let auditinfo = unsafe { auditinfo.assume_init() }; + println!("auid={}", auditinfo.ai_auid); println!("mask.success=0x{:x}", auditinfo.ai_mask.am_success); println!("mask.failure=0x{:x}", auditinfo.ai_mask.am_failure); diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 937187097..396131982 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -71,7 +71,6 @@ mod platform { use self::winapi::um::winbase; use self::winapi::um::winnt; use std::fs::OpenOptions; - use std::mem; use std::os::windows::prelude::*; use std::path::Path; use uucore::crash; @@ -99,8 +98,7 @@ mod platform { } unsafe fn find_first_volume() -> (String, winnt::HANDLE) { - #[allow(deprecated)] - let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = mem::uninitialized(); + let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = [0; minwindef::MAX_PATH]; let handle = winapi::um::fileapi::FindFirstVolumeW( name.as_mut_ptr(), name.len() as minwindef::DWORD, @@ -118,8 +116,7 @@ mod platform { let (first_volume, next_volume_handle) = find_first_volume(); let mut volumes = vec![first_volume]; loop { - #[allow(deprecated)] - let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = mem::uninitialized(); + let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = [0; minwindef::MAX_PATH]; if winapi::um::fileapi::FindNextVolumeW( next_volume_handle, name.as_mut_ptr(),