Skip to content

Commit 7519a60

Browse files
committed
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
2 parents 65ebfec + 21abed5 commit 7519a60

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

sha1_name.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -542,20 +542,20 @@ static void find_abbrev_len_for_pack(struct packed_git *p,
542542
/*
543543
* first is now the position in the packfile where we would insert
544544
* mad->hash if it does not exist (or the position of mad->hash if
545-
* it does exist). Hence, we consider a maximum of three objects
545+
* it does exist). Hence, we consider a maximum of two objects
546546
* nearby for the abbreviation length.
547547
*/
548548
mad->init_len = 0;
549549
if (!match) {
550-
nth_packed_object_oid(&oid, p, first);
551-
extend_abbrev_len(&oid, mad);
550+
if (nth_packed_object_oid(&oid, p, first))
551+
extend_abbrev_len(&oid, mad);
552552
} else if (first < num - 1) {
553-
nth_packed_object_oid(&oid, p, first + 1);
554-
extend_abbrev_len(&oid, mad);
553+
if (nth_packed_object_oid(&oid, p, first + 1))
554+
extend_abbrev_len(&oid, mad);
555555
}
556556
if (first > 0) {
557-
nth_packed_object_oid(&oid, p, first - 1);
558-
extend_abbrev_len(&oid, mad);
557+
if (nth_packed_object_oid(&oid, p, first - 1))
558+
extend_abbrev_len(&oid, mad);
559559
}
560560
mad->init_len = mad->cur_len;
561561
}

0 commit comments

Comments
 (0)