X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fstdlib%2Fbsearch.c;h=fe050ea30a223f4dd45070adae43cd59ac8a2243;hb=bec42ef393c0ad64e699a901ab0746d16bfde251;hp=61d89367e7b9140fa7dc067558427dc2aeed223c;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/stdlib/bsearch.c b/src/stdlib/bsearch.c index 61d89367..fe050ea3 100644 --- a/src/stdlib/bsearch.c +++ b/src/stdlib/bsearch.c @@ -7,13 +7,13 @@ void *bsearch(const void *key, const void *base, size_t nel, size_t width, int ( while (nel > 0) { try = (char *)base + width*(nel/2); sign = cmp(key, try); - if (!sign) return try; - else if (nel == 1) break; - else if (sign < 0) + if (sign < 0) { nel /= 2; - else { - base = try; - nel -= nel/2; + } else if (sign > 0) { + base = (char *)try + width; + nel -= nel/2+1; + } else { + return try; } } return NULL;