SIGFPE and x86
Eric Blake <[email protected]>
| Newsgroups | gmane.comp.gnu.m4.patches |
|---|---|
| Message-ID | <[email protected]> |
I'm checking this in; yet another case of a missing port from branch-1_4 (fixed 6 months ago in 1.4.5, no less). 2007-04-03 Eric Blake <[email protected]> * modules/m4.c (numb_ratio, numb_divide, numb_modulo): Avoid SIGFPE on x86 architectures. Reported by Ralf Wildenhues. Index: modules/m4.c =================================================================== RCS file: /sources/m4/m4/modules/m4.c,v retrieving revision 1.105 diff -u -r1.105 m4.c --- modules/m4.c 2 Apr 2007 12:06:23 -0000 1.105 +++ modules/m4.c 3 Apr 2007 21:01:00 -0000 @@ -1095,9 +1095,13 @@ #define numb_negate(x) ((x) = (- (x))) #define numb_times(x, y) ((x) = ((x) * (y))) -#define numb_ratio(x, y) ((x) = ((x) / ((y)))) -#define numb_divide(x, y) (*(x) = (*(x) / (*(y)))) -#define numb_modulo(c, x, y) (*(x) = (*(x) % *(y))) +/* Be careful of x86 SIGFPE. */ +#define numb_ratio(x, y) \ + (((y) == -1) ? (numb_negate (x)) : ((x) /= (y))) +#define numb_divide(x, y) \ + ((*(y) == -1) ? (numb_negate (*(y))) : (*(x) /= *(y))) +#define numb_modulo(c, x, y) \ + ((*(y) == -1) ? (*(x) = numb_ZERO) : (*(x) %= *(y))) /* numb_invert is only used in the context of x**-y, which integral math does not support. */ #define numb_invert(x) return NEGATIVE_EXPONENT