This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: ubsan: csky: left shift cannot be represented in type 'int'
- From: Michael Matz <matz at suse dot de>
- To: Alan Modra <amodra at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Wed, 11 Dec 2019 14:12:17 +0000 (UTC)
- Subject: Re: ubsan: csky: left shift cannot be represented in type 'int'
- References: <20191211005428.GA32672@bubble.grove.modra.org>
Hi,
On Wed, 11 Dec 2019, Alan Modra wrote:
> if (dis_info.info->endian == BFD_ENDIAN_BIG)
> - while (n--)
> - val |= buf[n] << (n*8);
> - else
> for (i = 0; i < n; i++)
> - val |= buf[i] << (i*8);
> + val = val << 8 | (buf[i] & 0xff);
> + else
> + for (i = n - 1; i >= 0; i--)
> + val = val << 8 | (buf[i] & 0xff);
But the '& 0xff' is really a no-op here, as you said: buf[i] is unsigned
char.
Ciao,
Michael.