std: Avoid overflowing in the midpoint calculation in upperBound

This commit is contained in:
T. M 2024-05-22 01:16:45 +00:00 committed by Andrew Kelley
parent 0039cb7ef2
commit d6eac43a5b

View File

@ -616,7 +616,7 @@ pub fn upperBound(
var right: usize = items.len; var right: usize = items.len;
while (left < right) { while (left < right) {
const mid = (right + left) / 2; const mid = left + (right - left) / 2;
if (!lessThan(context, key, items[mid])) { if (!lessThan(context, key, items[mid])) {
left = mid + 1; left = mid + 1;
} else { } else {