Skip to content

Commit 135c733

Browse files
committed
InternPool: fix crash in rehashTrackedInsts
When a shard has zero elements, we don't need to reserve any capacity.
1 parent bd0ace5 commit 135c733

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/InternPool.zig

+3-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ pub fn rehashTrackedInsts(
314314

315315
// We know how big each shard must be, so ensure we have the capacity we need.
316316
for (ip.shards) |*shard| {
317-
const want_capacity = std.math.ceilPowerOfTwo(u32, shard.mutate.tracked_inst_map.len * 5 / 3) catch unreachable;
317+
const want_capacity = if (shard.mutate.tracked_inst_map.len == 0) 0 else cap: {
318+
break :cap std.math.ceilPowerOfTwo(u32, shard.mutate.tracked_inst_map.len * 5 / 3) catch unreachable;
319+
};
318320
const have_capacity = shard.shared.tracked_inst_map.header().capacity; // no acquire because we hold the mutex
319321
if (have_capacity >= want_capacity) {
320322
@memset(shard.shared.tracked_inst_map.entries[0..have_capacity], .{ .value = .none, .hash = undefined });

0 commit comments

Comments
 (0)