mirror of
https://git.proxmox.com/git/proxmox
synced 2025-10-05 22:01:43 +00:00
replace std::mem::uninitialized
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
e59456e0b7
commit
45b5839e7e
@ -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");
|
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 {
|
for i in 0..4 {
|
||||||
addr[3 - i] = (hex_nibble(hex[i * 2])? << 4) + hex_nibble(hex[i * 2 + 1])?;
|
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");
|
bail!("Error while converting hex string to IPv6 address: unexpected string length");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut addr: [u8; 16] = unsafe { std::mem::uninitialized() };
|
let mut addr = std::mem::MaybeUninit::<[u8; 16]>::uninit();
|
||||||
for i in 0..16 {
|
let addr = unsafe {
|
||||||
addr[i] = (hex_nibble(hex[i * 2])? << 4) + hex_nibble(hex[i * 2 + 1])?;
|
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))
|
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");
|
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 {
|
for i in 0..4 {
|
||||||
bytes[i] = (hex_nibble(hex[i * 2])? << 4) + hex_nibble(hex[i * 2 + 1])?;
|
bytes[i] = (hex_nibble(hex[i * 2])? << 4) + hex_nibble(hex[i * 2 + 1])?;
|
||||||
}
|
}
|
||||||
|
@ -201,12 +201,12 @@ impl<R: io::Read> ReadExt for R {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn read_host_value<T: Endian>(&mut self) -> io::Result<T> {
|
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(
|
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>(),
|
std::mem::size_of::<T>(),
|
||||||
))?;
|
))?;
|
||||||
Ok(value)
|
Ok(value.assume_init())
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn read_le_value<T: Endian>(&mut self) -> io::Result<T> {
|
unsafe fn read_le_value<T: Endian>(&mut self) -> io::Result<T> {
|
||||||
|
Loading…
Reference in New Issue
Block a user