bucket_map: get_from_bytes should check alignment (#31444)

This commit is contained in:
Brooks 2023-05-02 15:17:36 -04:00 committed by GitHub
parent d6f65ccc27
commit 26809522b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -426,12 +426,14 @@ impl<T: Copy + 'static> IndexEntryPlaceInBucket<T> {
fn get_from_bytes<T>(item_slice: &[u8]) -> &T {
debug_assert!(std::mem::size_of::<T>() <= item_slice.len());
let item = item_slice.as_ptr() as *const T;
debug_assert!(item as usize % std::mem::align_of::<T>() == 0);
unsafe { &*item }
}
fn get_mut_from_bytes<T>(item_slice: &mut [u8]) -> &mut T {
debug_assert!(std::mem::size_of::<T>() <= item_slice.len());
let item = item_slice.as_mut_ptr() as *mut T;
debug_assert!(item as usize % std::mem::align_of::<T>() == 0);
unsafe { &mut *item }
}