From 205c426a9bb387204a21165e2275e31c32248035 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 11 Dec 2019 08:37:53 +1030 Subject: [PATCH] ubsan: s12z: left shift cannot be represented in type 'int' * s12z-opc.c (z_decode_signed_value): Avoid signed overflow. --- opcodes/ChangeLog | 4 ++++ opcodes/s12z-opc.c | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index ddf8cd00724..a8e1d30a9d4 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,7 @@ +2019-12-11 Alan Modra + + * s12z-opc.c (z_decode_signed_value): Avoid signed overflow. + 2019-12-11 Alan Modra * ns32k-dis.c (bit_extract): Use unsigned arithmetic. diff --git a/opcodes/s12z-opc.c b/opcodes/s12z-opc.c index 3e0c0e0582c..044c72a21ca 100644 --- a/opcodes/s12z-opc.c +++ b/opcodes/s12z-opc.c @@ -410,9 +410,7 @@ z_decode_signed_value (struct mem_read_abstraction_base *mra, int offset, int i; uint32_t value = 0; for (i = 0; i < size; ++i) - { - value |= buffer[i] << (8 * (size - i - 1)); - } + value = (value << 8) | buffer[i]; if (buffer[0] & 0x80) { -- 2.30.2