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.
+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
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;
}