From 4f7170f8a34f39ce32abaa1d6d3357e597e3863a Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Wed, 27 May 2026 02:14:38 -0700 Subject: [PATCH] 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. --- lib/std/heap/BrkAllocator.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/heap/BrkAllocator.zig b/lib/std/heap/BrkAllocator.zig index 1f0c88635f945be4ec5708901e4b7b3ccb21bfb3..9cb18673fe38e2acb8644e8dd41c041324b986d4 100644 --- a/lib/std/heap/BrkAllocator.zig +++ b/lib/std/heap/BrkAllocator.zig @@ -45,7 +45,7 @@ const size_class_count = math.log2(bigpage_size) - min_class; /// 1 - 2 bigpages /// 2 - 4 bigpages /// etc. -const big_size_class_count = math.log2(bigpage_count); +const big_size_class_count = math.log2(bigpage_count) + 1; fn alloc(ctx: *anyopaque, len: usize, alignment: Alignment, return_address: usize) ?[*]u8 { _ = ctx; -- 2.54.0