This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: [PATCH] readelf: handle_core_item large right shift triggers undefined behaviour.
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Fri, 04 Sep 2015 09:33:38 +0200
- Subject: 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