summaryrefslogtreecommitdiff
path: root/modules/m4.c
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2007-04-03 21:06:16 +0000
committerEric Blake <ebb9@byu.net>2007-10-06 07:08:21 -0600
commit0272fa99f3cfa800daa5b8a8222611ad8d315937 (patch)
treeb3c4b421967663f188146d7b7e40d690350ea92b /modules/m4.c
parent8b29cfdba57ed8308fcf6cebe8fafffe5f483d9d (diff)
downloadm4-0272fa99f3cfa800daa5b8a8222611ad8d315937.tar.gz
* modules/m4.c (numb_ratio, numb_divide, numb_modulo): Avoid
SIGFPE on x86 architectures. Reported by Ralf Wildenhues.
Diffstat (limited to 'modules/m4.c')
-rw-r--r--modules/m4.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/m4.c b/modules/m4.c
index c190240e..1cec2953 100644
--- a/modules/m4.c
+++ b/modules/m4.c
@@ -1095,9 +1095,13 @@ M4BUILTIN_HANDLER (translit)
#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