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>
René Scharfe committed
Nov 1, 2016 at 09:49 UTC
3e98919a188e36f34c1a20e23ecf2ff1f5da75c9
1 file changed
+2
-1
sha1_name.c
+2
-1
@@ -474,7 +474,8 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)
474
{
475
static int bufno;
476
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);
479
find_unique_abbrev_r(hex, sha1, len);
480
return hex;
481
}