{dynamic,fixed}_index: replace mem::uninitialized

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-08-22 11:35:35 +02:00
parent f93b55b057
commit 5e58e1bb7d
2 changed files with 19 additions and 6 deletions

View File

@ -141,10 +141,17 @@ impl DynamicIndexReader {
};
let end = unsafe { *(self.index.add(pos*40) as *const u64) };
let mut digest: [u8; 32] = unsafe { std::mem::uninitialized() };
unsafe { std::ptr::copy_nonoverlapping(self.index.add(pos*40+8), digest.as_mut_ptr(), 32); }
Ok((start, end, digest))
let mut digest = std::mem::MaybeUninit::<[u8; 32]>::uninit();
unsafe {
std::ptr::copy_nonoverlapping(
self.index.add(pos*40+8),
(*digest.as_mut_ptr()).as_mut_ptr(),
32,
);
}
Ok((start, end, unsafe { digest.assume_init() }))
}
#[inline]

View File

@ -153,10 +153,16 @@ impl FixedIndexReader {
end = self.size;
}
let mut digest: [u8; 32] = unsafe { std::mem::uninitialized() };
unsafe { std::ptr::copy_nonoverlapping(self.index.add(pos*32), digest.as_mut_ptr(), 32); }
let mut digest = std::mem::MaybeUninit::<[u8; 32]>::uninit();
unsafe {
std::ptr::copy_nonoverlapping(
self.index.add(pos*32),
(*digest.as_mut_ptr()).as_mut_ptr(),
32,
);
}
Ok((start, end, digest))
Ok((start, end, unsafe { digest.assume_init() }))
}
#[inline]