# InternPool: fix segfault in \`rehashTrackedInsts\` · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/42dac40b3feeabe39b5f191d1e72d247327133ba)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 42dac40b3feeabe39b5f191d1e72d247327133ba

Requested commit: 42dac40b3feeabe39b5f191d1e72d247327133ba

Commit: 42dac40b3feeabe39b5f191d1e72d247327133ba

Tree: 1839a029e92e2fe818334e54bf0946ec73b1717b

Author: mlugg

Committer: Matthew Lugg

## Message

```
InternPool: fix segfault in `rehashTrackedInsts`

The `.empty` map in a shard is weird: it claims to have capacity 1, but
you're not actually allowed to actually use that capacity. That's fine
for the normal insertion algorithm, because it always resizes to a
higher capacity when inserting the initial element. However,
`rehashTrackedInsts` was not aware of this caveat, so sometimes tried to
store to the single element of the `empty` map.

This system exists to avoid an extra branch in the main resizing logic
(since `new_cap = old_cap * 2` only works if the capacity is never
non-zero). However, it's fine for `rehashTrackedInsts` to have an extra
branch to handle this case, since it's literally called once per update.

```

## Parents

- [497592c9b45a94fb7b6028bf45b80f183e395a9b](https://git.cafe/gitcafe/zig/commit/497592c9b45a94fb7b6028bf45b80f183e395a9b?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/42dac40b3feeabe39b5f191d1e72d247327133ba?format=markdown)
