Move vector.c to the new error handling Remove "redundant" check for v->_cmp in wrapper function git_vector_bsearch(). Signed-off-by: schu <schu-github@schulog.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
diff --git a/src/vector.c b/src/vector.c
index d0b0c5c..1ddc26e 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -106,7 +106,7 @@ int git_vector_bsearch2(git_vector *v, git_vector_cmp key_lookup, const void *ke
/* need comparison function to sort the vector */
if (v->_cmp == NULL)
- return GIT_ENOTFOUND;
+ return git__throw(GIT_ENOTFOUND, "Can't sort vector. No comparison function set");
git_vector_sort(v);
@@ -114,7 +114,7 @@ int git_vector_bsearch2(git_vector *v, git_vector_cmp key_lookup, const void *ke
if (find != NULL)
return (int)(find - v->contents);
- return GIT_ENOTFOUND;
+ return git__throw(GIT_ENOTFOUND, "Can't find element");
}
int git_vector_search2(git_vector *v, git_vector_cmp key_lookup, const void *key)
@@ -128,7 +128,7 @@ int git_vector_search2(git_vector *v, git_vector_cmp key_lookup, const void *key
return i;
}
- return GIT_ENOTFOUND;
+ return git__throw(GIT_ENOTFOUND, "Can't find element");
}
static int strict_comparison(const void *a, const void *b)
@@ -143,9 +143,6 @@ int git_vector_search(git_vector *v, const void *entry)
int git_vector_bsearch(git_vector *v, const void *key)
{
- if (v->_cmp == NULL)
- return GIT_ENOTFOUND;
-
return git_vector_bsearch2(v, v->_cmp, key);
}
@@ -156,7 +153,7 @@ int git_vector_remove(git_vector *v, unsigned int idx)
assert(v);
if (idx >= v->length || v->length == 0)
- return GIT_ENOTFOUND;
+ return git__throw(GIT_ENOTFOUND, "Can't remove element. Index out of bounds");
for (i = idx; i < v->length - 1; ++i)
v->contents[i] = v->contents[i + 1];