merge from open-source master
authorThe Android Open Source Project <initial-contribution@android.com>
Wed, 31 Mar 2010 21:24:25 +0000 (14:24 -0700)
committerThe Android Open Source Project <initial-contribution@android.com>
Wed, 31 Mar 2010 21:24:25 +0000 (14:24 -0700)
Change-Id: I950e9aca87cbb0c35099b1d53cff6378bd0f26f4

libc/stdlib/bsearch.c

index 8193d27c60496519df5cf1bb6600e4167f6f79ef..7eb63255f18d7a8adc52aa34c6a296b999ccd9cc 100644 (file)
@@ -56,11 +56,11 @@ bsearch(const void *key, const void *base0, size_t nmemb, size_t size,
        for (lim = nmemb; lim != 0; lim >>= 1) {
                p = base + (lim >> 1) * size;
                cmp = (*compar)(key, p);
-               if (cmp == 0)
-                       return ((void *)p);
                if (cmp > 0) {  /* key > p: move right */
                        base = (char *)p + size;
                        lim--;
+               } else if (cmp == 0) {
+                       return ((void *)p);
                } /* else move left */
        }
        return (NULL);