Re: [PATCH 1/2] avoid shifting signed integers 31 bits
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Dec 31, 2015, 05:10 UTC
- Message-ID
- <CACsJy8CAAqZFQCfadUov7DFhSgh=dtGfE-onbXZQXO-0Y2652g@mail.gmail.com>
- In-Reply-To
- <20151229063545.GA30340@sigill.intra.peff.net>
On Tue, Dec 29, 2015 at 1:35 PM, Jeff King <peff@peff.net> wrote:
Show 7 quoted lines
> 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)
-- Duy