summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-03-06 16:14:31 -0800
committerRussell Belfer <arrbee@arrbee.com>2012-03-06 16:27:13 -0800
commitae9e29fde7e7d1c0c3e95bdabbb5c96fc71b1c71 (patch)
tree65d8215f898fc30b579b72d815e6adc78823dd6c /src/util.c
parentcb8a79617b15e347f26d21cedde0f2b8670c1876 (diff)
downloadlibgit2-ae9e29fde7e7d1c0c3e95bdabbb5c96fc71b1c71.tar.gz
Migrating diff to new error handling
Ended up migrating a bunch of upstream functions as well including vector, attr_file, and odb in order to get this to work right.
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;
}
/**