aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-12-10 23:53:57 +1030
committerAlan Modra <amodra@gmail.com>2019-12-11 11:39:25 +1030
commitf8a87c78e671b6e89c1d6dccdb2f99a34ddc23be (patch)
treeba4cfe8e96d39b324ab7dccb454cf320ba296923
parent159653d8c0bcc45b479e4329c2e5f304fa942280 (diff)
downloadgdb-f8a87c78e671b6e89c1d6dccdb2f99a34ddc23be.zip
gdb-f8a87c78e671b6e89c1d6dccdb2f99a34ddc23be.tar.gz
gdb-f8a87c78e671b6e89c1d6dccdb2f99a34ddc23be.tar.bz2
ubsan: h8300: left shift cannot be represented in type 'int'
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.
-rw-r--r--opcodes/ChangeLog5
-rw-r--r--opcodes/h8300-dis.c5
2 files changed, 8 insertions, 2 deletions
diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index 946c620..8d48b5a 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,5 +1,10 @@
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
past end of operands array.
diff --git a/opcodes/h8300-dis.c b/opcodes/h8300-dis.c
index 75d429e..c99b9f3 100644
--- a/opcodes/h8300-dis.c
+++ b/opcodes/h8300-dis.c
@@ -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]));