From eac7ff680ce7a9f95bc88daaa7c0339f2bf494b8 Mon Sep 17 00:00:00 2001 From: Skgland Date: Sat, 25 Apr 2026 16:39:53 +0200 Subject: [PATCH] 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 --- src/arena.rs | 5 ++++- src/types.rs | 5 ----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/arena.rs b/src/arena.rs index 1b5cd3e5..ffb92fb7 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -283,7 +283,10 @@ pub trait ArenaAllocated { Self::Payload: Sized, { TypedArenaPtr(NonNull::new_unchecked( - ptr.payload_offset().cast_mut().cast::(), + ptr.get_ptr() + .byte_add(Self::header_offset_from_payload()) + .cast_mut() + .cast::(), )) } diff --git a/src/types.rs b/src/types.rs index 994a6a27..bcf67a4a 100644 --- a/src/types.rs +++ b/src/types.rs @@ -754,11 +754,6 @@ impl UntypedArenaPtr { } } - #[inline] - pub fn payload_offset(self) -> *const u8 { - unsafe { self.get_ptr().byte_add(size_of::()).cast() } - } - /// # Safety /// - this UntypedArenaPtr actual pointee type is T /// - the pointer must be non-null -- 2.54.0