ubsan: csky: left shift cannot be represented in type 'int'
In the following buf is an unsigned char array, so elements are promoted to int before arithmetic operations. 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); * csky-dis.c (csky_chars_to_number): Rewrite. Avoid signed overflow when collecting bytes of a number.
This commit is contained in:
parent
c202f69e51
commit
d93bba9e0d
|
@ -1,3 +1,8 @@
|
|||
2019-12-11 Alan Modra <amodra@gmail.com>
|
||||
|
||||
* csky-dis.c (csky_chars_to_number): Rewrite. Avoid signed
|
||||
overflow when collecting bytes of a number.
|
||||
|
||||
2019-12-11 Alan Modra <amodra@gmail.com>
|
||||
|
||||
* cris-dis.c (print_with_operands): Avoid signed integer
|
||||
|
|
|
@ -140,11 +140,11 @@ csky_chars_to_number (unsigned char * buf, int n)
|
|||
unsigned int val = 0;
|
||||
|
||||
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);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue