1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Harden softer against invalid comparers

This commit is contained in:
Brian Fiete 2024-10-29 12:34:26 -04:00
parent 12640fd2b7
commit 74294567e7

View file

@ -219,8 +219,23 @@ namespace System.Collections
while (left < right)
{
while (comparer(keys[++left], pivot) < 0) {}
while (comparer(pivot, keys[--right]) < 0) {}
while (true)
{
left++;
if (left >= mCount)
Runtime.FatalError("Illegal comparer method. Comparer(lhs, rhs) must equal -Comparer(rhs, lhs).");
if (comparer(keys[++left], pivot) >= 0)
break;
}
while (true)
{
right--;
if (right < 0)
Runtime.FatalError("Illegal comparer method. Comparer(lhs, rhs) must equal -Comparer(rhs, lhs).");
if (comparer(pivot, keys[right]) >= 0)
break;
}
if(left >= right)
break;