* ubsan: signed integer multiply overflow
@ 2022-01-01 5:18 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-01-01 5:18 UTC (permalink / raw)
To: binutils
9223371018427387904 * 2 cannot be represented in type 'long', yes, but
we don't care.
* expr.c (expr): Avoid signed overflow.
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:
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-01-01 5:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-01 5:18 ubsan: signed integer multiply overflow Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).