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:
Skgland
2026-04-25 16:39:53 +02:00
parent b4db85c8c3
commit eac7ff680c
2 changed files with 4 additions and 6 deletions

View File

@@ -283,7 +283,10 @@ pub trait ArenaAllocated {
Self::Payload: Sized,
{
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>(),
))
}

View File

@@ -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
/// - this UntypedArenaPtr actual pointee type is T
/// - the pointer must be non-null