From 5afa80e9a8e6585eeaac44ca51be9c6b2471bf80 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 11 Dec 2019 13:11:07 +1030 Subject: [PATCH] Re: ubsan: ns32k: left shift cannot be represented in type * ns32k-dis.c (sign_extend): Correct last patch. --- opcodes/ChangeLog | 4 ++++ opcodes/ns32k-dis.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index c1fce7f33cc..5345dfb2bf7 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,7 @@ +2019-12-11 Alan Modra + + * ns32k-dis.c (sign_extend): Correct last patch. + 2019-12-11 Alan Modra * vax-dis.c (NEXTLONG): Avoid signed overflow. diff --git a/opcodes/ns32k-dis.c b/opcodes/ns32k-dis.c index 5e6f0964b7a..e43fff712ab 100644 --- a/opcodes/ns32k-dis.c +++ b/opcodes/ns32k-dis.c @@ -327,8 +327,8 @@ bit_copy (bfd_byte *buffer, int offset, int count, char *to) static int sign_extend (unsigned int value, unsigned int bits) { - unsigned int sign = 1u << bits; - return ((value & (sign - 1)) ^ sign) - sign; + unsigned int sign = 1u << (bits - 1); + return ((value & (sign + sign - 1)) ^ sign) - sign; } static void -- 2.30.2