summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2004-06-22 19:21:34 +0000
committerotto <otto@openbsd.org>2004-06-22 19:21:34 +0000
commit4e297bc3c4b53744e5a3a4ac204c8c28f30b6081 (patch)
tree1fb74cc912b6f2854560893215e2ee3cce911c5e
parentSpacing. ok krw@ (diff)
downloadwireguard-openbsd-4e297bc3c4b53744e5a3a4ac204c8c28f30b6081.tar.xz
wireguard-openbsd-4e297bc3c4b53744e5a3a4ac204c8c28f30b6081.zip
Do not generate floating point exception followed by a core dump
on div or mod by zero, print error message instead. ok espie@
-rw-r--r--usr.bin/m4/parser.y18
1 files changed, 15 insertions, 3 deletions
diff --git a/usr.bin/m4/parser.y b/usr.bin/m4/parser.y
index 09fd1270865..a0742cb5eee 100644
--- a/usr.bin/m4/parser.y
+++ b/usr.bin/m4/parser.y
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: parser.y,v 1.1 2004/05/12 21:17:03 espie Exp $ */
+/* $OpenBSD: parser.y,v 1.2 2004/06/22 19:21:34 otto Exp $ */
/*
* Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
*
@@ -40,8 +40,20 @@ top : expr { end_result = $1; }
expr : expr '+' expr { $$ = $1 + $3; }
| expr '-' expr { $$ = $1 - $3; }
| expr '*' expr { $$ = $1 * $3; }
- | expr '/' expr { $$ = $1 / $3; }
- | expr '%' expr { $$ = $1 % $3; }
+ | expr '/' expr {
+ if ($3 == 0) {
+ yyerror("division by zero");
+ exit(1);
+ }
+ $$ = $1 / $3;
+ }
+ | expr '%' expr {
+ if ($3 == 0) {
+ yyerror("modulo zero");
+ exit(1);
+ }
+ $$ = $1 % $3;
+ }
| expr LSHIFT expr { $$ = $1 << $3; }
| expr RSHIFT expr { $$ = $1 >> $3; }
| expr '<' expr { $$ = $1 < $3; }