diff options
-rw-r--r-- | gas/ChangeLog | 4 | ||||
-rw-r--r-- | gas/config/tc-z80.c | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog index ff0f65c..e217c82 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,5 +1,9 @@ 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. * testsuite/gas/ppc/raw.d: Update to suit. diff --git a/gas/config/tc-z80.c b/gas/config/tc-z80.c index 47d1405..303296b 100644 --- a/gas/config/tc-z80.c +++ b/gas/config/tc-z80.c @@ -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 |