diff options
Diffstat (limited to 'src/util.c')
| -rw-r--r-- | src/util.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/util.c b/src/util.c index 1fb01170b..d2309124b 100644 --- a/src/util.c +++ b/src/util.c @@ -355,23 +355,26 @@ int git__bsearch( int (*compare)(const void *, const void *), size_t *position) { - int lim, cmp; + int lim, cmp = -1; void **part, **base = array; for (lim = array_len; lim != 0; lim >>= 1) { part = base + (lim >> 1); cmp = (*compare)(key, *part); if (cmp == 0) { - *position = (part - array); - return GIT_SUCCESS; - } else if (cmp > 0) { /* key > p; take right partition */ + base = part; + break; + } + if (cmp > 0) { /* key > p; take right partition */ base = part + 1; lim--; } /* else take left partition */ } - *position = (base - array); - return GIT_ENOTFOUND; + if (position) + *position = (base - array); + + return (cmp == 0) ? 0 : -1; } /** |
