Skip to content

Commit 13c5783

Browse files
committed
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.
1 parent 47fad0e commit 13c5783

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

crates/oxc_allocator/src/fixed_size.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111
};
1212

1313
const TWO_GIB: usize = 1 << 31;
14+
const FOUR_GIB: usize = 1 << 32;
1415

1516
// What we ideally want is an allocation 2 GiB in size, aligned on 4 GiB.
1617
// But system allocator on Mac OS refuses allocations with 4 GiB alignment.
@@ -68,7 +69,7 @@ impl FixedSizeAllocator {
6869
// SAFETY: `offset` is either 0 or `TWO_GIB`.
6970
// We allocated 4 GiB of memory, so adding `offset` to `alloc_ptr` is in bounds.
7071
let chunk_ptr = unsafe {
71-
let offset = alloc_ptr.as_ptr() as usize % ALLOC_SIZE;
72+
let offset = alloc_ptr.as_ptr() as usize % FOUR_GIB;
7273
alloc_ptr.add(offset)
7374
};
7475

0 commit comments

Comments
 (0)