bug-m4
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 1.4.9: wrong results in signed division


From: Eric Blake
Subject: Re: 1.4.9: wrong results in signed division
Date: Wed, 25 Apr 2007 14:03:33 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Eric Blake <ebb9 <at> byu.net> writes:

> 
> According to Cesar Strauss on 4/21/2007 5:30 PM:
> > Hi,
> > 
> > The eval macro in m4-1.4.9 gives wrong results in signed division:
> > 
> > $ ./m4
> > eval(-100/10)
> > 429496719
> > (expected: -10)
> 
> Indeed, this is a regression.  Thanks for the report.
> 
> 
> No, consider INT_MIN/-1.  With 2's complement, it is undefined according
> to C (there is no way to represent -INT_MIN in an int).

But I already took care of that the line before, so your patch was correct as 
is, after all.  I'm checking in this, which also adds a regression test to 
ensure it doesn't happen again, and porting the test changes to HEAD (which, 
fortunately, did not have the bug).

2007-04-25  Eric Blake  <address@hidden>

        Fix negative division within eval, regression of 2007-01-06.
        * doc/m4.texinfo (Eval): Catch this bug.
        * src/eval.c (mult_term): Fix it.
        * NEWS: Document this.
        * THANKS: Update.
        Reported by Cesar Strauss.

Index: NEWS
===================================================================
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.1.1.1.2.98
diff -u -r1.1.1.1.2.98 NEWS
--- NEWS        23 Apr 2007 19:41:10 -0000      1.1.1.1.2.98
+++ NEWS        25 Apr 2007 13:59:03 -0000
@@ -4,7 +4,8 @@
 
 Version 1.4.10 - ?? ??? 2007, by ????  (CVS version 1.4.9a)
 
-*
+* Fix regression introduced in 1.4.9 in the `eval' builtin when performing
+  division.
 
 Version 1.4.9 - 23 Mar 2007, by Eric Blake  (CVS version 1.4.8c)
 
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.1.1.1.2.122
diff -u -r1.1.1.1.2.122 m4.texinfo
--- doc/m4.texinfo      16 Mar 2007 12:30:50 -0000      1.1.1.1.2.122
+++ doc/m4.texinfo      25 Apr 2007 13:59:04 -0000
@@ -4966,6 +4966,12 @@
 @example
 eval(`-3 * 5')
 @result{}-15
+eval(`-99 / 10')
address@hidden
+eval(`-99 % 10')
address@hidden
+eval(`99 % -10')
address@hidden
 eval(index(`Hello world', `llo') >= 0)
 @result{}1
 eval(`0r1:0111 + 0b100 + 0r3:12')
@@ -4979,7 +4985,7 @@
 define(`foo', `666')
 @result{}
 eval(`foo / 6')
address@hidden:stdin:8: bad expression in eval: foo / 6
address@hidden:stdin:11: bad expression in eval: foo / 6
 @result{}
 eval(foo / 6)
 @result{}111
Index: src/eval.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/eval.c,v
retrieving revision 1.1.1.1.2.9
diff -u -r1.1.1.1.2.9 eval.c
--- src/eval.c  9 Jan 2007 16:12:43 -0000       1.1.1.1.2.9
+++ src/eval.c  25 Apr 2007 13:59:04 -0000
@@ -718,10 +718,10 @@
          if (v2 == 0)
            return DIVIDE_ZERO;
          else if (v2 == -1)
-           /* Avoid the x86 SIGFPE on INT_MIN / -1.  */
+           /* Avoid overflow, and the x86 SIGFPE on INT_MIN / -1.  */
            *v1 = (int32_t) -(uint32_t) *v1;
          else
-           *v1 = (int32_t) ((uint32_t) *v1 / (uint32_t) v2);
+           *v1 /= v2;
          break;
 
        case MODULO:







reply via email to

[Prev in Thread] Current Thread [Next in Thread]