uutils: Remove use of mem::uninitialized (#3808)

This commit is contained in:
5225225 2022-08-15 09:10:50 +01:00 committed by GitHub
parent e2bab1d515
commit c7b988c825
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View file

@ -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<audit::c_auditinfo_addr_t> = 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);

View file

@ -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(),