authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-08 10:52:45+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-08 10:53:51+00:00
log135c733eefa8cd43e84e7b39aa292359c680fe1e
tree47799969392c951b83cbdc683337a64353fd8a5f
parentbd0ace5c4e898d7b7370e0704b08c62f0b6020c5
signaturelock-open Commit is signed but in an unrecognized format.

InternPool: fix crash in `rehashTrackedInsts`

When a shard has zero elements, we don't need to reserve any capacity.

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

src/InternPool.zig+3-1
...@@ -314,7 +314,9 @@ pub fn rehashTrackedInsts(...@@ -314,7 +314,9 @@ pub fn rehashTrackedInsts(
314314
315 // We know how big each shard must be, so ensure we have the capacity we need.315 // We know how big each shard must be, so ensure we have the capacity we need.
316 for (ip.shards) |*shard| {316 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 };
318 const have_capacity = shard.shared.tracked_inst_map.header().capacity; // no acquire because we hold the mutex320 const have_capacity = shard.shared.tracked_inst_map.header().capacity; // no acquire because we hold the mutex
319 if (have_capacity >= want_capacity) {321 if (have_capacity >= want_capacity) {
320 @memset(shard.shared.tracked_inst_map.entries[0..have_capacity], .{ .value = .none, .hash = undefined });322 @memset(shard.shared.tracked_inst_map.entries[0..have_capacity], .{ .value = .none, .hash = undefined });