diff --git a/proxmox-sys/src/linux/procfs.rs b/proxmox-sys/src/linux/procfs.rs index e3aba536..48601da2 100644 --- a/proxmox-sys/src/linux/procfs.rs +++ b/proxmox-sys/src/linux/procfs.rs @@ -284,7 +284,7 @@ fn hexstr_to_ipv4addr>(hex: T) -> Result { bail!("Error while converting hex string to IPv4 address: unexpected string length"); } - let mut addr: [u8; 4] = unsafe { std::mem::uninitialized() }; + let mut addr = [0u8; 4]; for i in 0..4 { addr[3 - i] = (hex_nibble(hex[i * 2])? << 4) + hex_nibble(hex[i * 2 + 1])?; } @@ -344,10 +344,14 @@ fn hexstr_to_ipv6addr>(hex: T) -> Result { bail!("Error while converting hex string to IPv6 address: unexpected string length"); } - let mut addr: [u8; 16] = unsafe { std::mem::uninitialized() }; - for i in 0..16 { - addr[i] = (hex_nibble(hex[i * 2])? << 4) + hex_nibble(hex[i * 2 + 1])?; - } + let mut addr = std::mem::MaybeUninit::<[u8; 16]>::uninit(); + let addr = unsafe { + let ap = &mut *addr.as_mut_ptr(); + for i in 0..16 { + ap[i] = (hex_nibble(hex[i * 2])? << 4) + hex_nibble(hex[i * 2 + 1])?; + } + addr.assume_init() + }; Ok(Ipv6Addr::from(addr)) } @@ -367,7 +371,7 @@ fn hexstr_to_u32>(hex: T) -> Result { bail!("Error while converting hex string to u32: unexpected string length"); } - let mut bytes: [u8; 4] = unsafe { std::mem::uninitialized() }; + let mut bytes = [0u8; 4]; for i in 0..4 { bytes[i] = (hex_nibble(hex[i * 2])? << 4) + hex_nibble(hex[i * 2 + 1])?; } diff --git a/proxmox-tools/src/io/read.rs b/proxmox-tools/src/io/read.rs index 39d923a6..a81b7701 100644 --- a/proxmox-tools/src/io/read.rs +++ b/proxmox-tools/src/io/read.rs @@ -201,12 +201,12 @@ impl ReadExt for R { } unsafe fn read_host_value(&mut self) -> io::Result { - let mut value: T = std::mem::uninitialized(); + let mut value = std::mem::MaybeUninit::::uninit(); self.read_exact(std::slice::from_raw_parts_mut( - &mut value as *mut T as *mut u8, + value.as_mut_ptr() as *mut u8, std::mem::size_of::(), ))?; - Ok(value) + Ok(value.assume_init()) } unsafe fn read_le_value(&mut self) -> io::Result {