1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-24 23:36:12 +02:00

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 bb84735c 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 <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe 2016-11-01 09:49:07 +01:00 committed by Junio C Hamano
parent 4f03666ac6
commit 3e98919a18

View File

@ -474,7 +474,8 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)
{
static int bufno;
static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
char *hex = hexbuffer[3 & ++bufno];
char *hex = hexbuffer[bufno];
bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
find_unique_abbrev_r(hex, sha1, len);
return hex;
}