]> git.proxmox.com Git - proxmox.git/commitdiff
replace std::mem::uninitialized
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 21 Aug 2019 14:49:12 +0000 (16:49 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 21 Aug 2019 14:49:12 +0000 (16:49 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
proxmox-sys/src/linux/procfs.rs
proxmox-tools/src/io/read.rs

index e3aba536d0915e4299f93b4a96179fbf693aeceb..48601da29dfc15f3408cf65dbec776c0bd9ac6ad 100644 (file)
@@ -284,7 +284,7 @@ fn hexstr_to_ipv4addr<T: AsRef<[u8]>>(hex: T) -> Result<Ipv4Addr, Error> {
         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<T: AsRef<[u8]>>(hex: T) -> Result<Ipv6Addr, Error> {
         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<T: AsRef<[u8]>>(hex: T) -> Result<u32, Error> {
         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])?;
     }
index 39d923a647fb5deafb7e6aa8509930de435309bf..a81b7701146c06ecffa1a69506cb227b816f93b6 100644 (file)
@@ -201,12 +201,12 @@ impl<R: io::Read> ReadExt for R {
     }
 
     unsafe fn read_host_value<T: Endian>(&mut self) -> io::Result<T> {
-        let mut value: T = std::mem::uninitialized();
+        let mut value = std::mem::MaybeUninit::<T>::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::<T>(),
         ))?;
-        Ok(value)
+        Ok(value.assume_init())
     }
 
     unsafe fn read_le_value<T: Endian>(&mut self) -> io::Result<T> {