From 1ffae59fec60816ff364b4ade93c6fc2fc1571cf Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 7 Feb 2025 00:47:43 -0800 Subject: [PATCH] std.heap.SmpAllocator: fix using wrong size class indices --- lib/std/heap/SmpAllocator.zig | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/std/heap/SmpAllocator.zig b/lib/std/heap/SmpAllocator.zig index b4e7138291..c1c9ca5517 100644 --- a/lib/std/heap/SmpAllocator.zig +++ b/lib/std/heap/SmpAllocator.zig @@ -215,13 +215,11 @@ fn free(context: *anyopaque, memory: []u8, alignment: mem.Alignment, ra: usize) fn sizeClassIndex(len: usize, alignment: mem.Alignment) usize { return @max( - @bitSizeOf(usize) - @clz(len - 1), - @intFromEnum(alignment), - min_class, - ); + @bitSizeOf(usize) - @clz(len + (@sizeOf(usize) - 1)), + @intFromEnum(alignment) + 1, + ) - min_class; } fn slotSize(class: usize) usize { - const Log2USize = std.math.Log2Int(usize); - return @as(usize, 1) << @as(Log2USize, @intCast(class)); + return @as(usize, 1) << @intCast(class + min_class); }