Fix crash when doing a lookup on an empty map.
This commit is contained in:
@@ -483,6 +483,9 @@ static void resizeMap(WrenVM* vm, ObjMap* map, uint32_t capacity)
|
|||||||
|
|
||||||
uint32_t wrenMapFind(ObjMap* map, Value key)
|
uint32_t wrenMapFind(ObjMap* map, Value key)
|
||||||
{
|
{
|
||||||
|
// If there is no entry array (an empty map), we definitely won't find it.
|
||||||
|
if (map->capacity == 0) return UINT32_MAX;
|
||||||
|
|
||||||
// Figure out where to insert it in the table. Use open addressing and
|
// Figure out where to insert it in the table. Use open addressing and
|
||||||
// basic linear probing.
|
// basic linear probing.
|
||||||
uint32_t index = hashValue(key) % map->capacity;
|
uint32_t index = hashValue(key) % map->capacity;
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// This is a regression test to ensure map handles a null entry array.
|
||||||
|
|
||||||
|
var map = {}
|
||||||
|
IO.print(map["key"]) // expect: null
|
||||||
Reference in New Issue
Block a user