Re: [PATCH 1/2] avoid shifting signed integers 31 bits

2016-01-04 Thread Jeff King
On Mon, Jan 04, 2016 at 09:52:10AM -0800, Junio C Hamano wrote: > >> 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

Re: [PATCH 1/2] avoid shifting signed integers 31 bits

2016-01-04 Thread Junio C Hamano
Jeff King writes: > On Thu, Dec 31, 2015 at 12:10:33PM +0700, Duy Nguyen wrote: > >> On Tue, Dec 29, 2015 at 1:35 PM, Jeff King wrote: >> > We sometimes use 32-bit unsigned integers as bit-fields. >> > It's fine to access the MSB, because it's unsigned. However, >>

Re: [PATCH 1/2] avoid shifting signed integers 31 bits

2015-12-30 Thread Jeff King
On Thu, Dec 31, 2015 at 12:10:33PM +0700, Duy Nguyen wrote: > On Tue, Dec 29, 2015 at 1:35 PM, Jeff King 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

Re: [PATCH 1/2] avoid shifting signed integers 31 bits

2015-12-30 Thread Duy Nguyen
On Tue, Dec 29, 2015 at 1:35 PM, Jeff King 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,

Re: [PATCH 1/2] avoid shifting signed integers 31 bits

2015-12-29 Thread Junio C Hamano
Jeff King writes: > diff --git a/diff.h b/diff.h > index f7208ad..893f446 100644 > --- a/diff.h > +++ b/diff.h > @@ -91,7 +91,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct > diff_options *opt, void *data) > #define DIFF_OPT_DIRSTAT_BY_LINE (1 << 28) > #define

Re: [PATCH 1/2] avoid shifting signed integers 31 bits

2015-12-29 Thread Jeff King
On Tue, Dec 29, 2015 at 04:09:21PM -0800, Junio C Hamano wrote: > > diff --git a/diff.h b/diff.h > > index f7208ad..893f446 100644 > > --- a/diff.h > > +++ b/diff.h > > @@ -91,7 +91,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct > > diff_options *opt, void *data) > > #define

[PATCH 1/2] avoid shifting signed integers 31 bits

2015-12-28 Thread Jeff King
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