diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2015-06-10 10:59:56 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-06-10 10:59:56 +0200 |
commit | 969d4b703c910a8fd045baafbcd243b4c9825316 (patch) | |
tree | 19bcf8305c238a2a6156e184e34319c593def193 | |
parent | 878293f7e1d62b951aaa7dc106ca9c6783112d96 (diff) | |
download | libgit2-969d4b703c910a8fd045baafbcd243b4c9825316.tar.gz |
object: correct the expected ID size in prefix lookup
We take in a possibly partial ID by taking a length and working off of
that to figure out whether to just look up the object or ask the
backends for a prefix lookup.
Unfortunately we've been checking the size against `GIT_OID_HEXSZ` which
is the size of a *string* containing a full ID, whereas we need to check
against the size we can have when it's a 20-byte array.
Change the checks and comment to use `GIT_OID_RAWSZ` which is the
correct size of a git_oid to have when full.
-rw-r--r-- | src/object.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/object.c b/src/object.c index 1073559fd..a178e0ed3 100644 --- a/src/object.c +++ b/src/object.c @@ -129,10 +129,10 @@ int git_object_lookup_prefix( if (error < 0) return error; - if (len > GIT_OID_HEXSZ) - len = GIT_OID_HEXSZ; + if (len > GIT_OID_RAWSZ) + len = GIT_OID_RAWSZ; - if (len == GIT_OID_HEXSZ) { + if (len == GIT_OID_RAWSZ) { git_cached_obj *cached = NULL; /* We want to match the full id : we can first look up in the cache, @@ -172,9 +172,9 @@ int git_object_lookup_prefix( memcpy(short_oid.id, id->id, (len + 1) / 2); if (len % 2) short_oid.id[len / 2] &= 0xF0; - memset(short_oid.id + (len + 1) / 2, 0, (GIT_OID_HEXSZ - len) / 2); + memset(short_oid.id + (len + 1) / 2, 0, (GIT_OID_RAWSZ - len) / 2); - /* If len < GIT_OID_HEXSZ (a strict short oid was given), we have + /* If len < GIT_OID_RAWSZ (a strict short oid was given), we have * 2 options : * - We always search in the cache first. If we find that short oid is * ambiguous, we can stop. But in all the other cases, we must then |