catch intmin/-1 instead of dumping core on SIGFPE; from Jilles Tjoelker

This commit is contained in:
tg 2011-12-11 01:35:10 +00:00
parent ee73f691f0
commit 971b153933
2 changed files with 27 additions and 4 deletions

24
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.501 2011/12/10 13:34:14 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.502 2011/12/11 01:35:08 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -282,6 +282,28 @@ stdin:
expected-stdout:
5
---
name: arith-div-byzero
description:
Check division by zero errors out
stdin:
x=$(echo $((1 / 0)))
echo =$?.
expected-stdout:
=1.
expected-stderr-pattern:
/.*divisor/
---
name: arith-div-intmin-by-minusone
description:
Check division overflow errors out
stdin:
x=$(echo $((-2147483648 / -1)))
echo =$?.
expected-stdout:
=1.
expected-stderr-pattern:
/.*divisor/
---
name: arith-assop-assoc-1
description:
Check associativity of assignment-operator operator

7
expr.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.49 2011/09/07 15:24:14 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.50 2011/12/11 01:35:10 tg Exp $");
/* The order of these enums is constrained by the order of opinfo[] */
enum token {
@ -351,11 +351,12 @@ evalexpr(Expr_state *es, int prec)
} else if (op != O_TERN && op != O_LAND && op != O_LOR)
vr = intvar(es, evalexpr(es, prec - 1));
if ((op == O_DIV || op == O_MOD || op == O_DIVASN ||
op == O_MODASN) && vr->val.i == 0) {
op == O_MODASN) && (vr->val.i == 0 || (!es->natural &&
vr->val.i == -1 && vl->val.i == -2147483648))) {
if (es->noassign)
vr->val.i = 1;
else
evalerr(es, ET_STR, "zero divisor");
evalerr(es, ET_STR, "invalid divisor");
}
switch ((int)op) {
case O_TIMES: