[binutils-gdb] ubsan: moxie: left shift of negative value

Alan Modra amodra@sourceware.org
Mon Dec 16 07:11:00 GMT 2019


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

commit cf950fd4dd4581849a445a76b57514d72074927d
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Dec 16 09:57:22 2019 +1030

    ubsan: moxie: left shift of negative value
    
    Commit 8c9b4171877df didn't remove a glaring left shift of a number
    that had just been sign extended.
    
    	* moxie-dis.c (INST2OFFSET): Don't left shift a signed value.
    	(print_insn_moxie): Remove unnecessary cast.

Diff:
---
 opcodes/ChangeLog   | 5 +++++
 opcodes/moxie-dis.c | 5 ++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index 9e0d57b..2d1c9d3 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-16  Alan Modra  <amodra@gmail.com>
+
+	* moxie-dis.c (INST2OFFSET): Don't left shift a signed value.
+	(print_insn_moxie): Remove unnecessary cast.
+
 2019-12-12  Alan Modra  <amodra@gmail.com>
 
 	* csky-dis.c (csky_chars_to_number): Remove abort and unnecessary
diff --git a/opcodes/moxie-dis.c b/opcodes/moxie-dis.c
index cbfcf95..1d06e18 100644
--- a/opcodes/moxie-dis.c
+++ b/opcodes/moxie-dis.c
@@ -33,7 +33,7 @@ static void *stream;
 /* Macros to extract operands from the instruction word.  */
 #define OP_A(i) ((i >> 4) & 0xf)
 #define OP_B(i) (i & 0xf)
-#define INST2OFFSET(o) (((((o) & 0x3ff) ^ 0x200) - 0x200) << 1)
+#define INST2OFFSET(o) (((((o) & 0x3ff) ^ 0x200) - 0x200) * 2)
 
 static const char * reg_names[16] =
   { "$fp", "$sp", "$r0", "$r1", "$r2", "$r3", "$r4", "$r5",
@@ -210,8 +210,7 @@ print_insn_moxie (bfd_vma addr, struct disassemble_info * info)
 	{
 	case MOXIE_F3_PCREL:
 	  fpr (stream, "%s\t", opcode->name);
-	  info->print_address_func ((bfd_vma) (addr + INST2OFFSET(iword) + 2),
-				    info);
+	  info->print_address_func (addr + INST2OFFSET (iword) + 2, info);
 	  break;
         case MOXIE_BAD:
 	  fpr (stream, "bad");



More information about the Binutils-cvs mailing list