ubsan: h8300: left shift cannot be represented in type 'int'
authorAlan Modra <amodra@gmail.com>
Tue, 10 Dec 2019 13:23:57 +0000 (23:53 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 11 Dec 2019 01:09:25 +0000 (11:39 +1030)
This is
  *cst = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
data is unsigned char which promotes to int.

* h8300-dis.c (extract_immediate): Avoid signed overflow.
(bfd_h8_disassemble): Likewise.

opcodes/ChangeLog
opcodes/h8300-dis.c

index 946c6201106999b062fb67300505a7f97299692c..8d48b5a8cd2466cc95bbed55a0edaac3117f4b32 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-11  Alan Modra  <amodra@gmail.com>
+
+       * h8300-dis.c (extract_immediate): Avoid signed overflow.
+       (bfd_h8_disassemble): Likewise.
+
 2019-12-11  Alan Modra  <amodra@gmail.com>
 
        * d30v-dis.c (print_insn): Make opind unsigned.  Don't access
index 75d429e6204b7c8a6ec5a0472563a291367708a7..c99b9f349897a2f1a2378e8aa830b71b0072202c 100644 (file)
@@ -140,7 +140,8 @@ extract_immediate (FILE *stream,
       break;
     case L_32:
       *len = 32;
-      *cst = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
+      *cst = (((unsigned) data[0] << 24) + (data[1] << 16)
+             + (data[2] << 8) + data[3]);
       break;
     default:
       *len = 0;
@@ -530,7 +531,7 @@ bfd_h8_disassemble (bfd_vma addr, disassemble_info *info, int mach)
                {
                  int i = len / 2;
 
-                 cst[opnr] = ((data[i] << 24)
+                 cst[opnr] = (((unsigned) data[i] << 24)
                               | (data[i + 1] << 16)
                               | (data[i + 2] << 8)
                               | (data[i + 3]));