[binutils-gdb] ubsan: tc-z80.c:3656 shift exponent 32 is too large

Alan Modra amodra@sourceware.org
Wed Sep 2 08:46:44 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=01a6f9da644e52fbd644a8e8f58d58c0383118c8

commit 01a6f9da644e52fbd644a8e8f58d58c0383118c8
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Sep 2 10:26:31 2020 +0930

    ubsan: tc-z80.c:3656 shift exponent 32 is too large
    
            * config/tc-z80.c (is_overflow): Avoid too large shift.

Diff:
---
 gas/ChangeLog       | 4 ++++
 gas/config/tc-z80.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index d6b58b48527..641b68de66a 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,7 @@
+2020-09-02  Alan Modra  <amodra@gmail.com>
+
+	* config/tc-z80.c (is_overflow): Avoid too large shift.
+
 2020-09-02  Alan Modra  <amodra@gmail.com>
 
 	* config/tc-sparc.c (in_signed_range): Use an unsigned type for
diff --git a/gas/config/tc-z80.c b/gas/config/tc-z80.c
index 45fcd6fbf74..2e17d005522 100644
--- a/gas/config/tc-z80.c
+++ b/gas/config/tc-z80.c
@@ -3653,7 +3653,7 @@ md_assemble (char *str)
 static int
 is_overflow (long value, unsigned bitsize)
 {
-  long fieldmask = (1UL << bitsize) - 1;
+  long fieldmask = (2UL << (bitsize - 1)) - 1;
   long signmask = ~fieldmask;
   long a = value & fieldmask;
   long ss = a & signmask;


More information about the Binutils-cvs mailing list