projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
dns: handle early eof in tcp fallback
[musl]
/
src
/
stdlib
/
bsearch.c
diff --git
a/src/stdlib/bsearch.c
b/src/stdlib/bsearch.c
index
61d8936
..
fe050ea
100644
(file)
--- 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);
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;
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;
}
}
return NULL;