mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-03-09 13:38:51 -04:00
fix: Use unaligned read as copy_nonoverlapping requires alignment (#1278)
This commit is contained in:
parent
9d5c21ae7e
commit
226c662da6
1 changed files with 3 additions and 5 deletions
|
@ -234,14 +234,12 @@ impl FastApiOneByteString {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Default> FastApiTypedArray<T> {
|
impl<T: Default> FastApiTypedArray<T> {
|
||||||
|
/// Performs an unaligned-safe read of T from the underlying data.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn get(&self, index: usize) -> T {
|
pub fn get(&self, index: usize) -> T {
|
||||||
debug_assert!(index < self.length);
|
debug_assert!(index < self.length);
|
||||||
let mut t: T = Default::default();
|
// SAFETY: src is valid for reads, and is a valid value for T
|
||||||
unsafe {
|
unsafe { ptr::read_unaligned(self.data.add(index)) }
|
||||||
ptr::copy_nonoverlapping(self.data.add(index), &mut t, 1);
|
|
||||||
}
|
|
||||||
t
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue