summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-09-26 12:00:07 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-09-26 18:46:41 (GMT)
commit59e4e34f6977f83c3a3842178da6358a5d130eb6 (patch)
treeb7a0219bfc313daefa6b023c8ba7d95a83cf0204
parent0016043bf46f4b85054c61f9000ccc58d0ef4ad7 (diff)
downloadgit-59e4e34f6977f83c3a3842178da6358a5d130eb6.zip
git-59e4e34f6977f83c3a3842178da6358a5d130eb6.tar.gz
git-59e4e34f6977f83c3a3842178da6358a5d130eb6.tar.bz2
get_short_sha1: NUL-terminate hex prefix
We store the hex prefix in a 40-byte buffer with the prefix itself followed by 40-minus-len "x" characters. These x's serve no purpose, and the lack of NUL termination makes the prefix string annoying to use. Let's just terminate it. Note that this is in contrast to the binary prefix, which _must_ be zero-padded, because we look at the whole thing during a binary search to find the first potential match in each pack index. The loose-object hex search cannot use the same trick because it has to do a linear walk through the unsorted results of readdir() (and even if it could, you'd want zeroes instead of x's). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--sha1_name.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/sha1_name.c b/sha1_name.c
index bd10700..bbfa1a0 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -14,7 +14,7 @@ typedef int (*disambiguate_hint_fn)(const unsigned char *, void *);
struct disambiguate_state {
int len; /* length of prefix in hex chars */
- char hex_pfx[GIT_SHA1_HEXSZ];
+ char hex_pfx[GIT_SHA1_HEXSZ + 1];
unsigned char bin_pfx[GIT_SHA1_RAWSZ];
disambiguate_hint_fn fn;
@@ -291,7 +291,6 @@ static int init_object_disambiguation(const char *name, int len,
return -1;
memset(ds, 0, sizeof(*ds));
- memset(ds->hex_pfx, 'x', GIT_SHA1_HEXSZ);
for (i = 0; i < len ;i++) {
unsigned char c = name[i];
@@ -313,6 +312,7 @@ static int init_object_disambiguation(const char *name, int len,
}
ds->len = len;
+ ds->hex_pfx[len] = '\0';
prepare_alt_odb();
return 0;
}
@@ -346,7 +346,7 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
status = finish_object_disambiguation(&ds, sha1);
if (!quietly && (status == SHORT_NAME_AMBIGUOUS))
- return error("short SHA1 %.*s is ambiguous.", ds.len, ds.hex_pfx);
+ return error("short SHA1 %s is ambiguous.", ds.hex_pfx);
return status;
}