aboutsummaryrefslogtreecommitdiff
path: root/opcodes
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-12-16 10:31:34 +1030
committerAlan Modra <amodra@gmail.com>2019-12-16 17:33:53 +1030
commitcedfc77485dbb566619dc1e2d729ce0a70d1a4ad (patch)
tree1831ca7e415295691de2a88b77c25a09e8f0cc85 /opcodes
parent4bdb25fe6902963ca9cf91d6b2688cf888527bf8 (diff)
downloadgdb-cedfc77485dbb566619dc1e2d729ce0a70d1a4ad.zip
gdb-cedfc77485dbb566619dc1e2d729ce0a70d1a4ad.tar.gz
gdb-cedfc77485dbb566619dc1e2d729ce0a70d1a4ad.tar.bz2
ubsan: bfin: left shift of negative value
* bfin-dis.c (fmtconst, fmtconst_val): Avoid signed overflow.
Diffstat (limited to 'opcodes')
-rw-r--r--opcodes/ChangeLog4
-rw-r--r--opcodes/bfin-dis.c17
2 files changed, 12 insertions, 9 deletions
diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index 65ef685..ca47606 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,5 +1,9 @@
2019-12-16 Alan Modra <amodra@gmail.com>
+ * bfin-dis.c (fmtconst, fmtconst_val): Avoid signed overflow.
+
+2019-12-16 Alan Modra <amodra@gmail.com>
+
* nds32-dis.c (print_insn16, print_insn32): Remove forward decls.
(struct objdump_disasm_info): Delete.
(nds32_parse_audio_ext, nds32_parse_opcode): Cast result of
diff --git a/opcodes/bfin-dis.c b/opcodes/bfin-dis.c
index 711f7e1..19ce426 100644
--- a/opcodes/bfin-dis.c
+++ b/opcodes/bfin-dis.c
@@ -128,7 +128,8 @@ fmtconst (const_forms_t cf, TIword x, bfd_vma pc, disassemble_info *outf)
if (constant_formats[cf].pcrel)
x = SIGNEXTEND (x, constant_formats[cf].nbits);
- ea = (x + constant_formats[cf].offset) << constant_formats[cf].scale;
+ ea = x + constant_formats[cf].offset;
+ ea = ea << constant_formats[cf].scale;
if (constant_formats[cf].pcrel)
ea += pc;
@@ -152,17 +153,14 @@ fmtconst (const_forms_t cf, TIword x, bfd_vma pc, disassemble_info *outf)
{
int nb = constant_formats[cf].nbits + 1;
- x = x | (1 << constant_formats[cf].nbits);
+ x = x | (1ul << constant_formats[cf].nbits);
x = SIGNEXTEND (x, nb);
}
else if (constant_formats[cf].issigned)
x = SIGNEXTEND (x, constant_formats[cf].nbits);
- if (constant_formats[cf].offset)
- x += constant_formats[cf].offset;
-
- if (constant_formats[cf].scale)
- x <<= constant_formats[cf].scale;
+ x += constant_formats[cf].offset;
+ x = (unsigned long) x << constant_formats[cf].scale;
if (constant_formats[cf].decimal)
sprintf (buf, "%*li", constant_formats[cf].leading, x);
@@ -186,7 +184,8 @@ fmtconst_val (const_forms_t cf, unsigned int x, unsigned int pc)
if (constant_formats[cf].pcrel)
x = SIGNEXTEND (x, constant_formats[cf].nbits);
- ea = (x + constant_formats[cf].offset) << constant_formats[cf].scale;
+ ea = x + constant_formats[cf].offset;
+ ea = ea << constant_formats[cf].scale;
if (constant_formats[cf].pcrel)
ea += pc;
@@ -197,7 +196,7 @@ fmtconst_val (const_forms_t cf, unsigned int x, unsigned int pc)
if (constant_formats[cf].negative)
{
int nb = constant_formats[cf].nbits + 1;
- x = x | (1u << constant_formats[cf].nbits);
+ x = x | (1ul << constant_formats[cf].nbits);
x = SIGNEXTEND (x, nb);
}
else if (constant_formats[cf].issigned)