summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2022-01-01 13:52:53 +1030
committerAlan Modra <amodra@gmail.com>2022-01-01 14:22:11 +1030
commit487b0ff02ddafeb27641c7674d4c8b3c9f62c6c3 (patch)
tree928951564fb255e8745bdffb86f2b16e0e809938
parentad3d14c47e872fcd13d83c9a255266c7027c8e16 (diff)
downloadbinutils-gdb-487b0ff02ddafeb27641c7674d4c8b3c9f62c6c3.tar.gz
ubsan: signed integer multiply overflow
9223371018427387904 * 2 cannot be represented in type 'long', yes, but we don't care. * expr.c (expr): Avoid signed overflow.
-rw-r--r--gas/expr.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/gas/expr.c b/gas/expr.c
index 03caa91f4d1..618927a605f 100644
--- a/gas/expr.c
+++ b/gas/expr.c
@@ -1959,7 +1959,12 @@ expr (int rankarg, /* Larger # is higher rank. */
switch (op_left)
{
default: goto general;
- case O_multiply: resultP->X_add_number *= v; break;
+ case O_multiply:
+ /* Do the multiply as unsigned to silence ubsan. The
+ result is of course the same when we throw away high
+ bits of the result. */
+ resultP->X_add_number *= (valueT) v;
+ break;
case O_divide: resultP->X_add_number /= v; break;
case O_modulus: resultP->X_add_number %= v; break;
case O_left_shift: