From 13c5783e5e1cc0119c424bedd0bddf97fe14f815 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 15 Jul 2025 15:09:52 +0000 Subject: [PATCH] fix(allocator): fix `FixedSizeAllocator` pointer maths (#12299) Fix a bug with calculating pointer to start of `Allocator` which crept in when buffer size changed in #12277. --- crates/oxc_allocator/src/fixed_size.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/oxc_allocator/src/fixed_size.rs b/crates/oxc_allocator/src/fixed_size.rs index a52e2032b2e17..dd04b6eff103d 100644 --- a/crates/oxc_allocator/src/fixed_size.rs +++ b/crates/oxc_allocator/src/fixed_size.rs @@ -11,6 +11,7 @@ use crate::{ }; const TWO_GIB: usize = 1 << 31; +const FOUR_GIB: usize = 1 << 32; // What we ideally want is an allocation 2 GiB in size, aligned on 4 GiB. // But system allocator on Mac OS refuses allocations with 4 GiB alignment. @@ -68,7 +69,7 @@ impl FixedSizeAllocator { // SAFETY: `offset` is either 0 or `TWO_GIB`. // We allocated 4 GiB of memory, so adding `offset` to `alloc_ptr` is in bounds. let chunk_ptr = unsafe { - let offset = alloc_ptr.as_ptr() as usize % ALLOC_SIZE; + let offset = alloc_ptr.as_ptr() as usize % FOUR_GIB; alloc_ptr.add(offset) };