This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC, v2] Fix PR symtab/15391
- From: Pedro Alves <palves at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Tue, 14 May 2013 15:31:12 +0100
- Subject: Re: [RFC, v2] Fix PR symtab/15391
- References: <87hai57jsc dot fsf at fleche dot redhat dot com>
On 05/14/2013 02:50 PM, Tom Tromey wrote:
> + if (TYPE_LENGTH (value_type (value)) < sizeof (LONGEST))
> + {
> + LONGEST nbits = 8 * TYPE_LENGTH (value_type (value));
> + LONGEST m1 = -1;
> +
> + if (((byte_offset >> (nbits - 1)) & 1) != 0)
> + byte_offset |= m1 << nbits;
> + }
I believe left-shifting a negative number is actually undefined
behavior. It's more usual/idiomatic to do sign extension like:
LONGEST nbits = 8 * TYPE_LENGTH (value_type (value));
int signbit = 1U << nbits;
byte_offset = (byte_offset ^ signbit) - signbit;
--
Pedro Alves