Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Fix out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Oct 12, 2019
1 parent 6d568ad commit 5d04012
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,11 @@ private ref TValue FindValueOrNull(TKey key)
{
// Should be a while loop https://github.com/dotnet/coreclr/issues/15476
// Test in if to drop range check for following array access
if ((uint)i >= (uint)entries.Length || (entries[i].hashCode == hashCode && EqualityComparer<TKey>.Default.Equals(entries[i].key, key)))
if ((uint)i >= (uint)entries.Length)
{
break; // Not found
}
else if (entries[i].hashCode == hashCode && EqualityComparer<TKey>.Default.Equals(entries[i].key, key))
{
value = ref entries[i].value;
break;
Expand All @@ -384,7 +388,11 @@ private ref TValue FindValueOrNull(TKey key)
{
// Should be a while loop https://github.com/dotnet/coreclr/issues/15476
// Test in if to drop range check for following array access
if ((uint)i >= (uint)entries.Length || (entries[i].hashCode == hashCode && defaultComparer.Equals(entries[i].key, key)))
if ((uint)i >= (uint)entries.Length)
{
break; // Not found
}
else if (entries[i].hashCode == hashCode && defaultComparer.Equals(entries[i].key, key))
{
value = ref entries[i].value;
break;
Expand All @@ -410,8 +418,11 @@ private ref TValue FindValueOrNull(TKey key)
{
// Should be a while loop https://github.com/dotnet/coreclr/issues/15476
// Test in if to drop range check for following array access
if ((uint)i >= (uint)entries.Length ||
(entries[i].hashCode == hashCode && comparer.Equals(entries[i].key, key)))
if ((uint)i >= (uint)entries.Length)
{
break; // Not found
}
else if (entries[i].hashCode == hashCode && comparer.Equals(entries[i].key, key))
{
value = ref entries[i].value;
break;
Expand Down

0 comments on commit 5d04012

Please sign in to comment.