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:
Alan Modra 2019-12-10 23:37:03 +10:30
parent c202f69e51
commit d93bba9e0d
2 changed files with 9 additions and 4 deletions

View File

@ -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

View File

@ -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;
}