From d6eac43a5b1f9d353ac4bdc24f3daf5ce4b1dc1b Mon Sep 17 00:00:00 2001 From: "T. M" Date: Wed, 22 May 2024 01:16:45 +0000 Subject: [PATCH] std: Avoid overflowing in the midpoint calculation in upperBound --- lib/std/sort.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/sort.zig b/lib/std/sort.zig index 03e9defd35..5edf06e2f7 100644 --- 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 {