Skip to content

Commit f718ec1

Browse files
Merge pull request #145 from dlang-community/fix_insert
Fix use-after-free when an insert causes a rehash
2 parents 257c041 + 29149d2 commit f718ec1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/containers/hashmap.d

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,18 @@ 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+
return &item;
506+
}
507+
assert(false);
508+
}
509+
else
510+
return n;
501511
}
502512

503513
/**

0 commit comments

Comments
 (0)