This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] readelf: handle_core_item large right shift triggers undefined behaviour.


On Thu, 2015-09-03 at 13:58 -0700, Roland McGrath wrote:
> What about:
> 	w >>= n % 32;
> 	w >>= (n - (n % 32)) % 32;
> ?

I don't think that works. For the interesting case n == 32, you won't
shift at all. Because both expressions (32 % 32) and ((32 - 0) % 32)
evaluate to zero.
I prefer the simpler: if (n < sizeof (w) * 8) w >>= n; else w = 0;
Which simply states what value we expect for w.

Cheers,

Mark

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]