mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-03-07 13:39:43 +08:00
ubsan errors when 32-bit bfd
A shift count exceeding the size of the value is undefined behaviour, and so is negating a signed LONG_MIN. * config/tc-z80.c (signed_overflow, unsigned_overflow): Avoid UB.
This commit is contained in:
parent
43f71bc5df
commit
03e689aaac
@ -1,3 +1,7 @@
|
||||
2021-06-19 Alan Modra <amodra@gmail.com>
|
||||
|
||||
* config/tc-z80.c (signed_overflow, unsigned_overflow): Avoid UB.
|
||||
|
||||
2021-06-19 Alan Modra <amodra@gmail.com>
|
||||
|
||||
* testsuite/gas/ppc/raw.s: Use 0 as pli constant.
|
||||
|
@ -3703,14 +3703,14 @@ md_assemble (char *str)
|
||||
static int
|
||||
signed_overflow (signed long value, unsigned bitsize)
|
||||
{
|
||||
signed long max = (signed long)(1UL << (bitsize-1));
|
||||
return value < -max || value >= max;
|
||||
signed long max = (signed long) ((1UL << (bitsize - 1)) - 1);
|
||||
return value < -max - 1 || value > max;
|
||||
}
|
||||
|
||||
static int
|
||||
unsigned_overflow (unsigned long value, unsigned bitsize)
|
||||
{
|
||||
return (value >> bitsize) != 0;
|
||||
return value >> (bitsize - 1) >> 1 != 0;
|
||||
}
|
||||
|
||||
static int
|
||||
|
Loading…
Reference in New Issue
Block a user