summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-01-31 09:34:52 -0800
committerEdward Thomson <ethomson@edwardthomson.com>2018-02-09 10:16:46 +0000
commit59d99adcdeef4b08c5aec7fb3b000831e4fe21c5 (patch)
tree09e0b89e530e1d1a551c20127349a027cff48b16
parentef9028642ab3805b139fbfed0244e48d96af3728 (diff)
downloadlibgit2-59d99adcdeef4b08c5aec7fb3b000831e4fe21c5.tar.gz
odb: check for alloc errors on hardcoded objects
It's unlikely that we'll fail to allocate a single byte, but let's check for allocation failures for good measure. Untangle `-1` being a marker of not having found the hardcoded odb object; use that to reflect actual errors.
-rw-r--r--src/odb.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/odb.c b/src/odb.c
index e4ea5871f..af38a8ef3 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -66,15 +66,21 @@ static git_otype odb_hardcoded_type(const git_oid *id)
return GIT_OBJ_BAD;
}
-static int odb_read_hardcoded(git_rawobj *raw, const git_oid *id)
+static int odb_read_hardcoded(bool *found, git_rawobj *raw, const git_oid *id)
{
- git_otype type = odb_hardcoded_type(id);
- if (type == GIT_OBJ_BAD)
- return -1;
+ git_otype type;
+
+ *found = false;
+
+ if ((type = odb_hardcoded_type(id)) == GIT_OBJ_BAD)
+ return 0;
raw->type = type;
raw->len = 0;
raw->data = git__calloc(1, sizeof(uint8_t));
+ GITERR_CHECK_ALLOC(raw->data);
+
+ *found = true;
return 0;
}
@@ -1012,8 +1018,10 @@ static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id,
bool found = false;
int error = 0;
- if (!only_refreshed && odb_read_hardcoded(&raw, id) == 0)
- found = true;
+ if (!only_refreshed) {
+ if ((error = odb_read_hardcoded(&found, &raw, id)) < 0)
+ return error;
+ }
for (i = 0; i < db->backends.length && !found; ++i) {
backend_internal *internal = git_vector_get(&db->backends, i);