git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Subject: [PATCH] hex: use unsigned index for ring buffer
Date: Sun, 23 Oct 2016 11:00:48 +0200	[thread overview]
Message-ID: <ebf769d4-771f-499e-c7fc-f0377d8df18e@web.de> (raw)

Overflow is defined for unsigned integers, but not for signed ones.
Make the ring buffer index in sha1_to_hex() unsigned to be on the
safe side.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
Hard to trigger, but probably even harder to diagnose once someone
somehow manages to do it on some uncommon architecture.

 hex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hex.c b/hex.c
index ab2610e..8c6c189 100644
--- a/hex.c
+++ b/hex.c
@@ -76,7 +76,7 @@ char *oid_to_hex_r(char *buffer, const struct object_id *oid)
 
 char *sha1_to_hex(const unsigned char *sha1)
 {
-	static int bufno;
+	static unsigned int bufno;
 	static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
 	return sha1_to_hex_r(hexbuffer[3 & ++bufno], sha1);
 }
-- 
2.10.1


             reply	other threads:[~2016-10-23  9:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-23  9:00 René Scharfe [this message]
2016-10-23  9:11 ` [PATCH] hex: use unsigned index for ring buffer Jeff King
2016-10-23 17:57   ` René Scharfe
2016-10-24 13:00     ` Jeff King
2016-10-24 17:15       ` Junio C Hamano
2016-10-24 17:27         ` Junio C Hamano
2016-10-24 22:33           ` René Scharfe
2016-10-24 23:53             ` Junio C Hamano
2016-10-25  0:30               ` Jeff King
2016-10-25 18:28                 ` Junio C Hamano
2016-10-25 18:33                   ` Jeff King
2016-10-25 18:37                     ` Junio C Hamano
2016-10-26 17:08                   ` René Scharfe
2016-10-26 17:53                     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ebf769d4-771f-499e-c7fc-f0377d8df18e@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).