mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
fix: Guard against uninitialized hashmap in key removal
Removing non-present keys is a supported operation on HashMaps, and most other operations are well-defined on uninitialized HashMaps. Currently, removing any key on an uninitialized HashMap will result in an 'Array index out of bounds' error. This change guards against such a case.
This commit is contained in:
committed by
Christoffer Lerno
parent
74b8da1e15
commit
4edaf603c9
@@ -369,6 +369,7 @@ fn void HashMap.free_internal(&map, void* ptr) @inline @private
|
||||
|
||||
fn bool HashMap.remove_entry_for_key(&map, Key key) @private
|
||||
{
|
||||
if (!map.count) return false;
|
||||
uint hash = rehash(key.hash());
|
||||
uint i = index_for(hash, map.table.len);
|
||||
Entry* prev = map.table[i];
|
||||
@@ -421,4 +422,4 @@ struct Entry
|
||||
Key key;
|
||||
Value value;
|
||||
Entry* next;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user