Skip to content

Commit

Permalink
Merge pull request #145 from dlang-community/fix_insert
Browse files Browse the repository at this point in the history
Fix use-after-free when an insert causes a rehash
  • Loading branch information
jcrapuchettes authored Apr 29, 2019
2 parents 257c041 + 29149d2 commit f718ec1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/containers/hashmap.d
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,18 @@ private:
if (modifyLength)
_length++;
if (shouldRehash())
{
rehash();
return n;
immutable newIndex = hashToIndex(hash, buckets.length);
foreach (ref item; buckets[newIndex])
{
if (item.hash == hash && item.key == key)
return &item;
}
assert(false);
}
else
return n;
}

/**
Expand Down

0 comments on commit f718ec1

Please sign in to comment.