]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ubsan: integer overflow in tc-i386.c:offset_in_range
authorAlan Modra <amodra@gmail.com>
Wed, 21 May 2025 08:27:04 +0000 (17:57 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 21 May 2025 23:12:12 +0000 (08:42 +0930)
or $9223372036854775808,%eax
runtime error: negation of -9223372036854775808 cannot be represented
in type 'offsetT' (aka 'long'); cast to an unsigned type to negate
this value to itself

* config/tc-i386.c (offset_in_range): Avoid signed overflow.

gas/config/tc-i386.c

index 162e28e03259efca14dc80e327b3a4a965a17e7b..25bbc5360a866f8526d6980f47cb497f42ee306a 100644 (file)
@@ -2990,7 +2990,7 @@ offset_in_range (offsetT val, int size)
     default: abort ();
     }
 
-  if ((val & ~mask) != 0 && (-val & ~mask) != 0)
+  if ((val & ~mask) != 0 && (-(addressT) val & ~mask) != 0)
     as_warn (_("0x%" PRIx64 " shortened to 0x%" PRIx64),
             (uint64_t) val, (uint64_t) (val & mask));