diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-12-08 10:52:45 +0000 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-12-08 10:53:51 +0000 |
| commit | 135c733eefa8cd43e84e7b39aa292359c680fe1e (patch) | |
| tree | 47799969392c951b83cbdc683337a64353fd8a5f /src/InternPool.zig | |
| parent | bd0ace5c4e898d7b7370e0704b08c62f0b6020c5 (diff) | |
| download | zig-135c733eefa8cd43e84e7b39aa292359c680fe1e.tar.gz zig-135c733eefa8cd43e84e7b39aa292359c680fe1e.zip | |
InternPool: fix crash in `rehashTrackedInsts`
When a shard has zero elements, we don't need to reserve any capacity.
Diffstat (limited to 'src/InternPool.zig')
| -rw-r--r-- | src/InternPool.zig | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig index 63cdd7cec8..bbbcb953f6 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -314,7 +314,9 @@ pub fn rehashTrackedInsts( // We know how big each shard must be, so ensure we have the capacity we need. for (ip.shards) |*shard| { - const want_capacity = std.math.ceilPowerOfTwo(u32, shard.mutate.tracked_inst_map.len * 5 / 3) catch unreachable; + const want_capacity = if (shard.mutate.tracked_inst_map.len == 0) 0 else cap: { + break :cap std.math.ceilPowerOfTwo(u32, shard.mutate.tracked_inst_map.len * 5 / 3) catch unreachable; + }; const have_capacity = shard.shared.tracked_inst_map.header().capacity; // no acquire because we hold the mutex if (have_capacity >= want_capacity) { @memset(shard.shared.tracked_inst_map.entries[0..have_capacity], .{ .value = .none, .hash = undefined }); |
