physfs.c
changeset 668 a5c80bd9549e
parent 663 65132f8a8692
child 679 ae75b5548364
--- a/physfs.c	Sat Oct 30 23:45:29 2004 +0000
+++ b/physfs.c	Sun Oct 31 12:20:00 2004 +0000
@@ -1305,19 +1305,26 @@
 {
     PHYSFS_uint32 hi = *pos - 1;
     PHYSFS_uint32 lo = 0;
-    PHYSFS_uint32 i = hi / 2;
+    PHYSFS_uint32 i = hi >> 1;
     int cmp;
 
+    assert(*pos != 0);  /* this doesn't work with empty lists! */
+
     while (hi != lo)
     {
         cmp = strcmp(list[i], str);
         if (cmp == 0)  /* it's in the list already. */
             return(1);
         else if (cmp < 0)
+        {
             hi = i;
+            i = lo + ((hi - lo) >> 1);
+        } /* else if */
         else
-            lo = i;
-        i = lo + ((hi - lo) / 2);
+        {
+            lo = i + 1;
+            i = lo + ((1 + hi - lo) >> 1);
+        } /* else */
     } /* while */
 
     /* hi == lo, check it in case it's the match... */