From 3d637ada5d1f4c18123e5f80014b7a3f27b40fd1 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Fri, 10 Nov 2023 07:30:09 +0530 Subject: [PATCH] fixes an overflow (for very large number of elements) in binary search --- rigctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rigctl.c b/rigctl.c index b1adbdc..a38d4a5 100644 --- a/rigctl.c +++ b/rigctl.c @@ -4539,7 +4539,8 @@ bool search(cat_command *commands, char cmd[2], int *index) { while (l <= r) { // go to the middle of the array[r:l] // and pick out the middle element. - int m = (l + r)/2; + // int m = (l + r)/2; + int m = l + (r - l)/2; // compare the command name in the middle element // with the one we are looking for. -- 2.45.2