summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-03-08 20:36:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-03-08 20:36:26 (GMT)
commit7519a60ffa3f811ec49fd9956e284ff90f3b1cf1 (patch)
tree7c86f3452ca5cfba9cb2fc75c744b3e5f56085c7
parent65ebfec5154c32e60efbec318e23110a1660809c (diff)
parent21abed500cb06bc54247cbc11def92739259bb70 (diff)
downloadgit-7519a60ffa3f811ec49fd9956e284ff90f3b1cf1.zip
git-7519a60ffa3f811ec49fd9956e284ff90f3b1cf1.tar.gz
git-7519a60ffa3f811ec49fd9956e284ff90f3b1cf1.tar.bz2
Merge branch 'ds/find-unique-abbrev-optim'
While finding unique object name abbreviation, the code may accidentally have read beyond the end of the array of object names in a pack. * ds/find-unique-abbrev-optim: sha1_name: fix uninitialized memory errors
-rw-r--r--sha1_name.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/sha1_name.c b/sha1_name.c
index e7c18ff..735c1c0 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -542,20 +542,20 @@ static void find_abbrev_len_for_pack(struct packed_git *p,
/*
* first is now the position in the packfile where we would insert
* mad->hash if it does not exist (or the position of mad->hash if
- * it does exist). Hence, we consider a maximum of three objects
+ * it does exist). Hence, we consider a maximum of two objects
* nearby for the abbreviation length.
*/
mad->init_len = 0;
if (!match) {
- nth_packed_object_oid(&oid, p, first);
- extend_abbrev_len(&oid, mad);
+ if (nth_packed_object_oid(&oid, p, first))
+ extend_abbrev_len(&oid, mad);
} else if (first < num - 1) {
- nth_packed_object_oid(&oid, p, first + 1);
- extend_abbrev_len(&oid, mad);
+ if (nth_packed_object_oid(&oid, p, first + 1))
+ extend_abbrev_len(&oid, mad);
}
if (first > 0) {
- nth_packed_object_oid(&oid, p, first - 1);
- extend_abbrev_len(&oid, mad);
+ if (nth_packed_object_oid(&oid, p, first - 1))
+ extend_abbrev_len(&oid, mad);
}
mad->init_len = mad->cur_len;
}