mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix error when HashMap.remove on uninitialized HashMap (#1629)
* HashMap: test removal on uninitialized * HashMap.remove_entry_for_key: return false on unintialized * test: switch to temp_init * release note
This commit is contained in:
@@ -482,6 +482,7 @@ fn void HashMap.free_internal(&map, void* ptr) @inline @private
|
|||||||
|
|
||||||
fn bool HashMap.remove_entry_for_key(&map, Key key) @private
|
fn bool HashMap.remove_entry_for_key(&map, Key key) @private
|
||||||
{
|
{
|
||||||
|
if (!map.count) return false;
|
||||||
uint hash = rehash(key.hash());
|
uint hash = rehash(key.hash());
|
||||||
uint i = index_for(hash, map.table.len);
|
uint i = index_for(hash, map.table.len);
|
||||||
Entry* prev = map.table[i];
|
Entry* prev = map.table[i];
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
- Fix issue writing a single byte in the WriteBuffer
|
- Fix issue writing a single byte in the WriteBuffer
|
||||||
- A distinct inline pointer type can now participate in pointer arithmetics.
|
- A distinct inline pointer type can now participate in pointer arithmetics.
|
||||||
- Support &a[0] returning the distinct type when applying it to a distinct of a pointer.
|
- Support &a[0] returning the distinct type when applying it to a distinct of a pointer.
|
||||||
|
- Fix error when calling `HashMap.remove` on uninitialized `HashMap`.
|
||||||
|
|
||||||
### Stdlib changes
|
### Stdlib changes
|
||||||
- Add `io::MultiReader`, `io::MultiWriter`, and `io::TeeReader` structs.
|
- Add `io::MultiReader`, `io::MultiWriter`, and `io::TeeReader` structs.
|
||||||
|
|||||||
@@ -53,4 +53,14 @@ fn void map()
|
|||||||
assert(tc.key == list[i].key);
|
assert(tc.key == list[i].key);
|
||||||
assert(tc.value == list[i].value);
|
assert(tc.value == list[i].value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn void map_remove()
|
||||||
|
{
|
||||||
|
Map m;
|
||||||
|
assert(!@ok(m.remove("A")));
|
||||||
|
m.temp_init();
|
||||||
|
assert(!@ok(m.remove("A")));
|
||||||
|
m.set("A", 0);
|
||||||
|
assert(@ok(m.remove("A")));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user