0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-21 15:04:33 -05:00

fix: Use unaligned read as copy_nonoverlapping requires alignment (#1278)

This commit is contained in:
Matt Mastracci 2023-07-11 08:07:47 -06:00 committed by GitHub
parent 9d5c21ae7e
commit 226c662da6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -234,14 +234,12 @@ impl FastApiOneByteString {
}
impl<T: Default> FastApiTypedArray<T> {
/// Performs an unaligned-safe read of T from the underlying data.
#[inline(always)]
pub fn get(&self, index: usize) -> T {
debug_assert!(index < self.length);
let mut t: T = Default::default();
unsafe {
ptr::copy_nonoverlapping(self.data.add(index), &mut t, 1);
}
t
// SAFETY: src is valid for reads, and is a valid value for T
unsafe { ptr::read_unaligned(self.data.add(index)) }
}
#[inline(always)]