]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
fixes an overflow (for very large number of elements) in binary search
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 10 Nov 2023 02:00:09 +0000 (07:30 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 10 Nov 2023 02:00:09 +0000 (07:30 +0530)
rigctl.c

index b1adbdce8ecff9f9db795d05b73e69ca88de0a4f..a38d4a5e955a91687d6dfdbf4e9631754a3aba6b 100644 (file)
--- 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.