ubsan: m68k: left shift cannot be represented in type 'int'
authorAlan Modra <amodra@gmail.com>
Tue, 10 Dec 2019 21:53:33 +0000 (08:23 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 11 Dec 2019 01:09:42 +0000 (11:39 +1030)
* m68k-dis.c (COERCE32): Cast value first.
(NEXTLONG, NEXTULONG): Avoid signed overflow.

opcodes/ChangeLog
opcodes/m68k-dis.c

index 8d48b5a8cd2466cc95bbed55a0edaac3117f4b32..ffe57a451489d9e8afc130fd983d85d92edf1965 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-11  Alan Modra  <amodra@gmail.com>
+
+       * m68k-dis.c (COERCE32): Cast value first.
+       (NEXTLONG, NEXTULONG): Avoid signed overflow.
+
 2019-12-11  Alan Modra  <amodra@gmail.com>
 
        * h8300-dis.c (extract_immediate): Avoid signed overflow.
index 7584541402b60b4489a9eae6f78531963cba76eb..6e913d7abd6e6a1485e804e9f98985dbce521717 100644 (file)
@@ -96,7 +96,7 @@ enum print_insn_arg_error
   while (0)
 
 /* Get a 4 byte signed integer.  */
-#define COERCE32(x) ((bfd_signed_vma) ((x) ^ 0x80000000) - 0x80000000)
+#define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000)
 
 #define NEXTLONG(p, val, ret_val)                                      \
   do                                                                   \
@@ -104,7 +104,8 @@ enum print_insn_arg_error
       p += 4;                                                          \
       if (!FETCH_DATA (info, p))                                       \
        return ret_val;                                                 \
-      val = COERCE32 ((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1]); \
+      val = COERCE32 (((((((unsigned) p[-4] << 8) + p[-3]) << 8)       \
+                       + p[-2]) << 8) + p[-1]);                        \
     }                                                                  \
   while (0)
 
@@ -115,7 +116,8 @@ enum print_insn_arg_error
       p += 4;                                                          \
       if (!FETCH_DATA (info, p))                                       \
        return PRINT_INSN_ARG_MEMORY_ERROR;                             \
-      val = (unsigned int) ((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1]); \
+      val = (((((((unsigned) p[-4] << 8) + p[-3]) << 8)                        \
+              + p[-2]) << 8) + p[-1]);                                 \
     }                                                                  \
   while (0)