{"thread":{"id":"44405","subject":"[PATCH] sha1_name: make wraparound of the index into ring-buffer explicit","startedAt":"2016-11-01T08:49:45Z","lastAt":"2016-11-01T15:04:36Z","messageCount":2,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"305221","messageId":"a1e2c4a4-4720-fc26-c866-6ab959543c3b@web.de","threadId":"44405","inReplyTo":null,"subject":"[PATCH] sha1_name: make wraparound of the index into ring-buffer explicit","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2016-11-01T08:49:07Z","receivedAt":"2016-11-01T08:49:45Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Overflow is defined for unsigned integers, but not for signed ones.\nWrap around explicitly for the new ring-buffer in find_unique_abbrev()\nas we did in bb84735c for the ones in sha1_to_hex() and get_pathname(),\nthus avoiding signed overflows and getting rid of the magic number 3.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n sha1_name.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 06409a3..73a915f 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -510,7 +510,8 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)\n {\n \tstatic int bufno;\n \tstatic char hexbuffer[4][GIT_SHA1_HEXSZ + 1];\n-\tchar *hex = hexbuffer[3 & ++bufno];\n+\tchar *hex = hexbuffer[bufno];\n+\tbufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);\n \tfind_unique_abbrev_r(hex, sha1, len);\n \treturn hex;\n }\n-- \n2.10.2\n\n"},{"id":"305227","messageId":"20161101150429.fohpchtlfvohzood@sigill.intra.peff.net","threadId":"44405","inReplyTo":"a1e2c4a4-4720-fc26-c866-6ab959543c3b@web.de","subject":"Re: [PATCH] sha1_name: make wraparound of the index into ring-buffer explicit","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-11-01T15:04:29Z","receivedAt":"2016-11-01T15:04:36Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Nov 01, 2016 at 09:49:07AM +0100, René Scharfe wrote:\n\n> Overflow is defined for unsigned integers, but not for signed ones.\n> Wrap around explicitly for the new ring-buffer in find_unique_abbrev()\n> as we did in bb84735c for the ones in sha1_to_hex() and get_pathname(),\n> thus avoiding signed overflows and getting rid of the magic number 3.\n\nThanks. I didn't mean to make you do this, but my procrastination won\nagain.\n\n> diff --git a/sha1_name.c b/sha1_name.c\n> index 06409a3..73a915f 100644\n> --- a/sha1_name.c\n> +++ b/sha1_name.c\n> @@ -510,7 +510,8 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)\n>  {\n>  \tstatic int bufno;\n>  \tstatic char hexbuffer[4][GIT_SHA1_HEXSZ + 1];\n> -\tchar *hex = hexbuffer[3 & ++bufno];\n> +\tchar *hex = hexbuffer[bufno];\n> +\tbufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);\n\nCode looks obviously correct (and it even does the \"start at 0\" thing).\n\n-Peff\n"}]}