git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Duy Nguyen <pclouds@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
	Christian Couder <christian.couder@gmail.com>
Subject: Re: [PATCH 1/2] avoid shifting signed integers 31 bits
Date: Thu, 31 Dec 2015 00:20:29 -0500	[thread overview]
Message-ID: <20151231052029.GA10238@sigill.intra.peff.net> (raw)
In-Reply-To: <CACsJy8CAAqZFQCfadUov7DFhSgh=dtGfE-onbXZQXO-0Y2652g@mail.gmail.com>

On Thu, Dec 31, 2015 at 12:10:33PM +0700, Duy Nguyen wrote:

> On Tue, Dec 29, 2015 at 1:35 PM, Jeff King <peff@peff.net> wrote:
> > We sometimes use 32-bit unsigned integers as bit-fields.
> > It's fine to access the MSB, because it's unsigned. However,
> > doing so as "1 << 31" is wrong, because the constant "1" is
> > a signed int, and we shift into the sign bit, causing
> > undefined behavior.
> >
> > We can fix this by using "1U" as the constant.
> 
> We have this in cache.h, should it be fixed as well?
> 
> /* CE_EXTENDED2 is for future extension */
> #define CE_EXTENDED2         (1 << 31)

Sort of. We don't actually use it, and since it's a macro, that means it
never even hits the compiler proper itself. So it's not a bug, but it's
a bug waiting to happen. :)

-Peff

  reply	other threads:[~2015-12-31  5:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-29  6:34 [PATCH 0/2] compiling with -fsanitize=undefined Jeff King
2015-12-29  6:35 ` [PATCH 1/2] avoid shifting signed integers 31 bits Jeff King
2015-12-30  0:09   ` Junio C Hamano
2015-12-30  4:25     ` Jeff King
2015-12-31  5:10   ` Duy Nguyen
2015-12-31  5:20     ` Jeff King [this message]
2016-01-04 17:52       ` Junio C Hamano
2016-01-04 23:32         ` Jeff King
2015-12-29  6:36 ` [PATCH 2/2] bswap: add NO_UNALIGNED_LOADS define Jeff King
2015-12-29  6:42   ` Eric Sunshine
2015-12-29  6:45     ` Jeff King
2015-12-29  6:44 ` [PATCH 0/2] compiling with -fsanitize=undefined Jeff King

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=20151231052029.GA10238@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    /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).