summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'patchsets/skey/1.1.5/06_all_binary-search.patch')
-rw-r--r--patchsets/skey/1.1.5/06_all_binary-search.patch36
1 files changed, 36 insertions, 0 deletions
diff --git a/patchsets/skey/1.1.5/06_all_binary-search.patch b/patchsets/skey/1.1.5/06_all_binary-search.patch
new file mode 100644
index 0000000..90e399c
--- /dev/null
+++ b/patchsets/skey/1.1.5/06_all_binary-search.patch
@@ -0,0 +1,36 @@
+Fix binary search.
+
+--- skey-1.1.5-orig/put.c
++++ skey-1.1.5/put.c
+@@ -2206,27 +2206,17 @@
+ {
+ int i, j;
+
+- for (;;) {
++ while (low <= high) {
+ i = (low + high) / 2;
+
+ if ((j = strncmp(w, Wp[i], 4)) == 0)
+ return i; /* Found it */
+- if (high == low + 1)
+- {
+- /* Avoid effects of integer truncation in /2 */
+- if (strncmp(w, Wp[high], 4) == 0)
+- return high;
+- else
+- return -1;
+- }
+-
+- if (low >= high)
+- return -1; /* I don't *think* this can happen... */
+ if (j < 0)
+- high = i; /* Search lower half */
++ high = i - 1; /* Search lower half */
+ else
+- low = i; /* Search upper half */
++ low = i + 1; /* Search upper half */
+ }
++ return -1;
+ }
+
+ static void insert(char *s, int x, int start, int length)