authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-05-27 02:14:38-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-03 02:24:15+02:00
log4f7170f8a34f39ce32abaa1d6d3357e597e3863a
treed81269815d986a7160975ee666b974cdb730a182
parentb0f124d46dfd719fc138ab140622f5f6b1aa65f0

BrkAllocator: Fix big_size_class_count holding the max index rather than count

Attempting to allocate > (1 GiB - @sizeOf(usize)) would previously hit index out-of-bounds due to the slot index coming out to 15 which is the same as the length of the big_frees array. The log2 gives the max index, not the count, so it needs the +1.

1 files changed, 1 insertions(+), 1 deletions(-)

lib/std/heap/BrkAllocator.zig+1-1
...@@ -45,7 +45,7 @@ const size_class_count = math.log2(bigpage_size) - min_class;...@@ -45,7 +45,7 @@ const size_class_count = math.log2(bigpage_size) - min_class;
45/// 1 - 2 bigpages45/// 1 - 2 bigpages
46/// 2 - 4 bigpages46/// 2 - 4 bigpages
47/// etc.47/// etc.
48const big_size_class_count = math.log2(bigpage_count);48const big_size_class_count = math.log2(bigpage_count) + 1;
4949
50fn alloc(ctx: *anyopaque, len: usize, alignment: Alignment, return_address: usize) ?[*]u8 {50fn alloc(ctx: *anyopaque, len: usize, alignment: Alignment, return_address: usize) ?[*]u8 {
51 _ = ctx;51 _ = ctx;