mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
std/lib/sort: avoid overflow in binary search
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
committed by
Christoffer Lerno
parent
dddeca1856
commit
0efb142c88
@@ -12,7 +12,7 @@ macro usz binarysearch_with(list, x, cmp)
|
||||
usz len = @len_from_list(list);
|
||||
for (usz j = len; i < j;)
|
||||
{
|
||||
usz half = (i + j) / 2;
|
||||
usz half = i + (j - i) / 2;
|
||||
$if $checks(cmp(list[0], list[0])):
|
||||
int res = cmp(list[half], x);
|
||||
$else
|
||||
|
||||
Reference in New Issue
Block a user