diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-06-22 19:21:35 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-06-22 19:21:35 +0000 |
commit | 7ac3abf53bfceb3ddbff62e06cccca6204cb7709 (patch) | |
tree | fc46f0c1ceddd9fd8361550faa18ba7ac8e70cd3 /usr.bin/m4 | |
parent | 2d63d4705fde93ae1a7f7c4d279e60813b5db38e (diff) |
Do not generate floating point exception followed by a core dump
on div or mod by zero, print error message instead.
ok espie@
Diffstat (limited to 'usr.bin/m4')
-rw-r--r-- | usr.bin/m4/parser.y | 18 |
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; } |