# std.hash_map: fetchRemove increment available · gitcafe/zig

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

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

Visibility: public

Requested revision: f04e65bc09ab77eafc317b2d2981970509aae6af

Requested commit: f04e65bc09ab77eafc317b2d2981970509aae6af

Commit: f04e65bc09ab77eafc317b2d2981970509aae6af

Tree: 707964d29fbc65bc693fe543a47c14f5231f4e52

Author: sentientwaffle

Committer: Veikka Tuominen

## Message

```
std.hash_map: fetchRemove increment available

To avoid leaking slots, `fetchRemove` must increment `available` (when the "fetch" succeeds).

Without the `available += 1`, the added test `"std.hash_map repeat fetchRemove"` fails with

    run test std-x86-linux-none-Debug: error: thread 432734 panic: integer overflow
    .../zig/lib/std/hash_map.zig:1365:28: 0x6471d5 in getOrPutAssumeCapacityAdapted__anon_47495 (test)
            self.available -= 1;
                           ^
    .../zig/lib/std/hash_map.zig:1308:62: 0x616950 in getOrPutAssumeCapacityContext (test)
            const result = self.getOrPutAssumeCapacityAdapted(key, ctx);
                                                             ^

Alternatively, `fetchRemove` could call `removeByIndex`, though that would entail calling `header()` twice instead of once.

```

## Parents

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

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