From: Alan Modra Date: Tue, 10 Dec 2019 13:23:57 +0000 (+1030) Subject: ubsan: h8300: left shift cannot be represented in type 'int' X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=f8a87c78e671b6e89c1d6dccdb2f99a34ddc23be;p=deliverable%2Fbinutils-gdb.git 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. --- diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 946c620110..8d48b5a8cd 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,8 @@ +2019-12-11 Alan Modra + + * h8300-dis.c (extract_immediate): Avoid signed overflow. + (bfd_h8_disassemble): Likewise. + 2019-12-11 Alan Modra * d30v-dis.c (print_insn): Make opind unsigned. Don't access diff --git a/opcodes/h8300-dis.c b/opcodes/h8300-dis.c index 75d429e620..c99b9f3498 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]));