summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-03-07 10:55:18 -0800
committerRussell Belfer <arrbee@arrbee.com>2012-03-07 10:55:18 -0800
commit6af24ce31f43c3621f11720704a078058665bc3f (patch)
tree9d180ee76c51c7fd41b7cd646254e114801770db /src/util.c
parente54d8d8972ddfa886bfcf1a078d253b632debc72 (diff)
parent998f7b3dd76afbf462785a757b24a3554ad8534d (diff)
downloadlibgit2-6af24ce31f43c3621f11720704a078058665bc3f.tar.gz
Merge pull request #590 from arrbee/new-error-handling
Migrating diff to new error handling
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c15
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;
}
/**