Skip to content

Commit 3e98919

Browse files
rscharfegitster
authored andcommitted
sha1_name: make wraparound of the index into ring-buffer explicit
Overflow is defined for unsigned integers, but not for signed ones. Wrap around explicitly for the new ring-buffer in find_unique_abbrev() as we did in bb84735 for the ones in sha1_to_hex() and get_pathname(), thus avoiding signed overflows and getting rid of the magic number 3. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4f03666 commit 3e98919

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

sha1_name.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)
474474
{
475475
static int bufno;
476476
static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
477-
char *hex = hexbuffer[3 & ++bufno];
477+
char *hex = hexbuffer[bufno];
478+
bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
478479
find_unique_abbrev_r(hex, sha1, len);
479480
return hex;
480481
}

0 commit comments

Comments
 (0)