This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: ubsan: csky: left shift cannot be represented in type 'int'


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.


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