1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-07 20:52:45 +02:00

(eval4): Detect overflow properly when multiplying INTMAX_MIN * -1.

This commit is contained in:
Paul Eggert
2006-06-08 02:53:25 +00:00
parent 0eef2e1e8b
commit cad27cdc2e
2 changed files with 9 additions and 2 deletions

View File

@@ -1,7 +1,12 @@
2006-06-06 Paul Eggert <eggert@cs.ucla.edu>
2006-06-07 Paul Eggert <eggert@cs.ucla.edu>
* Version 6.0-cvs.
* src/expr.c (eval4): Detect overflow properly when multiplying
INTMAX_MIN * -1.
2006-06-06 Paul Eggert <eggert@cs.ucla.edu>
* NEWS: The 'expr' command now detects and reports integer overflow.
(It would be better to use extended precision instead, but that
would be more work.)

View File

@@ -640,7 +640,9 @@ eval4 (bool evaluate)
if (fxn == multiply)
{
val = l->u.i * r->u.i;
if (! (l->u.i == 0 || val / l->u.i == r->u.i))
if (! (l->u.i == 0 || r->u.i == 0
|| ((val < 0) == ((l->u.i < 0) ^ (r->u.i < 0))
&& val / l->u.i == r->u.i)))
integer_overflow ('*');
}
else