commit 3518d22d5670a18e592a325bb6ee286427cc3d4c (tree)
parent b5e99b5295e74566689986ed48e30046028948f0
Author: T. M <pm2mtr@gmail.com>
Date: Wed, 22 May 2024 01:16:45 +0000
std: Avoid overflowing in the midpoint calculation in upperBound
Diffstat:
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/std/sort.zig b/lib/std/sort.zig
@@ -616,7 +616,7 @@ pub fn upperBound(
var right: usize = items.len;
while (left < right) {
- const mid = (right + left) / 2;
+ const mid = left + (right - left) / 2;
if (!lessThan(context, key, items[mid])) {
left = mid + 1;
} else {