summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>1999-09-16 20:19:35 +0000
committerMarc Espie <espie@cvs.openbsd.org>1999-09-16 20:19:35 +0000
commit11bfdccdb15a1e11d71fd52d99653b7dc969a35f (patch)
treeeeb67f4f8b30b5ea76458bd0f18d04e3203ff11c
parent07ed1176daca5784243c78e389e312a142604513 (diff)
Do something sensible with division by 0 in expr.
Noticed by aaron@.
-rw-r--r--usr.bin/m4/expr.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/usr.bin/m4/expr.c b/usr.bin/m4/expr.c
index 5089d60e9b0..d2e3fce9827 100644
--- a/usr.bin/m4/expr.c
+++ b/usr.bin/m4/expr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: expr.c,v 1.7 1999/09/14 08:35:16 espie Exp $ */
+/* $OpenBSD: expr.c,v 1.8 1999/09/16 20:19:34 espie Exp $ */
/* $NetBSD: expr.c,v 1.7 1995/09/28 05:37:31 tls Exp $ */
/*
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)expr.c 8.2 (Berkeley) 4/29/95";
#else
-static char rcsid[] = "$OpenBSD: expr.c,v 1.7 1999/09/14 08:35:16 espie Exp $";
+static char rcsid[] = "$OpenBSD: expr.c,v 1.8 1999/09/16 20:19:34 espie Exp $";
#endif
#endif /* not lint */
@@ -338,10 +338,16 @@ term()
vl *= vr;
break;
case '/':
- vl /= vr;
+ if (vr == 0)
+ errx(1, "division by zero in eval.");
+ else
+ vl /= vr;
break;
case '%':
- vl %= vr;
+ if (vr == 0)
+ errx(1, "modulo zero in eval.");
+ else
+ vl %= vr;
break;
}
}