This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ubsan: ns32k: left shift cannot be represented in type 'int'


	* ns32k-dis.c (bit_extract): Use unsigned arithmetic.
	(bit_extract_simple, sign_extend): Likewise.

diff --git a/opcodes/ns32k-dis.c b/opcodes/ns32k-dis.c
index 22a9389ecf..5e6f0964b7 100644
--- a/opcodes/ns32k-dis.c
+++ b/opcodes/ns32k-dis.c
@@ -262,8 +262,8 @@ list_search (int reg_value, const struct ns32k_option *optionP, char *result)
 static int
 bit_extract (bfd_byte *buffer, int offset, int count)
 {
-  int result;
-  int bit;
+  unsigned int result;
+  unsigned int bit;
 
   if (offset < 0 || count < 0)
     return 0;
@@ -291,8 +291,8 @@ bit_extract (bfd_byte *buffer, int offset, int count)
 static int
 bit_extract_simple (bfd_byte *buffer, int offset, int count)
 {
-  int result;
-  int bit;
+  unsigned int result;
+  unsigned int bit;
 
   if (offset < 0 || count < 0)
     return 0;
@@ -325,12 +325,10 @@ bit_copy (bfd_byte *buffer, int offset, int count, char *to)
 }
 
 static int
-sign_extend (int value, int bits)
+sign_extend (unsigned int value, unsigned int bits)
 {
-  value = value & ((1 << bits) - 1);
-  return (value & (1 << (bits - 1))
-	  ? value | (~((1 << bits) - 1))
-	  : value);
+  unsigned int sign = 1u << bits;
+  return ((value & (sign - 1)) ^ sign) - sign;
 }
 
 static void

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]