Skip to content

Commit bdaf3b9

Browse files
committed
Fix use-after-free when an insert causes a rehash
1 parent 257c041 commit bdaf3b9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/containers/hashmap.d

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,21 @@ private:
496496
if (modifyLength)
497497
_length++;
498498
if (shouldRehash())
499+
{
499500
rehash();
500-
return n;
501+
immutable newIndex = hashToIndex(hash, buckets.length);
502+
foreach (ref item; buckets[newIndex])
503+
{
504+
if (item.hash == hash && item.key == key)
505+
{
506+
item.value = value;
507+
return &item;
508+
}
509+
}
510+
assert(false);
511+
}
512+
else
513+
return n;
501514
}
502515

503516
/**

0 commit comments

Comments
 (0)