From: René Scharfe Date: Tue, 1 Nov 2016 08:49:07 +0000 (+0100) Subject: sha1_name: make wraparound of the index into ring-buffer explicit X-Git-Tag: v2.11.0-rc1~13^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/3e98919a188e36f34c1a20e23ecf2ff1f5da75c9?hp=--cc 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 Signed-off-by: Junio C Hamano --- 3e98919a188e36f34c1a20e23ecf2ff1f5da75c9 diff --git a/sha1_name.c b/sha1_name.c index 36ce9b9f45..45aa26b322 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -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; }