This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ubsan: microblaze: left shift cannot be represented in type 'int'


On 12/15/19 11:10 PM, Alan Modra wrote:
	* microblaze-dis.c (read_insn_microblaze): Avoid signed overflow.

diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
index 2b3aa8e078..5df7ae497e 100644
--- a/opcodes/microblaze-dis.c
+++ b/opcodes/microblaze-dis.c
@@ -200,9 +200,11 @@ read_insn_microblaze (bfd_vma memaddr,
      }
if (info->endian == BFD_ENDIAN_BIG)
-    inst = (ibytes[0] << 24) | (ibytes[1] << 16) | (ibytes[2] << 8) | ibytes[3];
+    inst = (((unsigned) ibytes[0] << 24) | (ibytes[1] << 16)
+	    | (ibytes[2] << 8) | ibytes[3]);
    else if (info->endian == BFD_ENDIAN_LITTLE)
-    inst = (ibytes[3] << 24) | (ibytes[2] << 16) | (ibytes[1] << 8) | ibytes[0];
+    inst = (((unsigned) ibytes[3] << 24) | (ibytes[2] << 16)
+	    | (ibytes[1] << 8) | ibytes[0]);
    else
      abort ();


OK

--
Michael Eager    eager@eagerm.com
1960 Park Blvd., Palo Alto, CA 94306


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]