fix ArenaPtr payload offset logic
the old logic would be incorrect if the payload has higher alignment than the ArenaHeader i.e. when there is padding between the ArenaHeader and the Payload
This commit is contained in:
@@ -283,7 +283,10 @@ pub trait ArenaAllocated {
|
|||||||
Self::Payload: Sized,
|
Self::Payload: Sized,
|
||||||
{
|
{
|
||||||
TypedArenaPtr(NonNull::new_unchecked(
|
TypedArenaPtr(NonNull::new_unchecked(
|
||||||
ptr.payload_offset().cast_mut().cast::<Self::Payload>(),
|
ptr.get_ptr()
|
||||||
|
.byte_add(Self::header_offset_from_payload())
|
||||||
|
.cast_mut()
|
||||||
|
.cast::<Self::Payload>(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -754,11 +754,6 @@ impl UntypedArenaPtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn payload_offset(self) -> *const u8 {
|
|
||||||
unsafe { self.get_ptr().byte_add(size_of::<ArenaHeader>()).cast() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// - this UntypedArenaPtr actual pointee type is T
|
/// - this UntypedArenaPtr actual pointee type is T
|
||||||
/// - the pointer must be non-null
|
/// - the pointer must be non-null
|
||||||
|
|||||||
Reference in New Issue
Block a user