From 2fb060368627dc29279d5ac969e6c3eb6b0e7ea3 Mon Sep 17 00:00:00 2001 From: jilles Date: Sat, 12 Feb 2011 23:44:05 +0000 Subject: sh: Detect dividing the smallest integer by -1. This overflows and on some architectures such as amd64 it generates SIGFPE. Generate an error on all architectures. --- bin/sh/arith_yacc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'bin/sh/arith_yacc.c') diff --git a/bin/sh/arith_yacc.c b/bin/sh/arith_yacc.c index 423e4e2..8aab8fb 100644 --- a/bin/sh/arith_yacc.c +++ b/bin/sh/arith_yacc.c @@ -125,6 +125,8 @@ static arith_t do_binop(int op, arith_t a, arith_t b) case ARITH_DIV: if (!b) yyerror("division by zero"); + if (a == ARITH_MIN && b == -1) + yyerror("divide error"); return op == ARITH_REM ? a % b : a / b; case ARITH_MUL: return a * b; -- cgit v1.1