From daa12e324da3d06e02e5e85bc27d5855273f2617 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 28 Mar 2013 08:40:32 +0000 Subject: Don't die with SIGFPE on INT_MIN / -1 or % -1. Instead make INT_MIN / -1 == INT_MIN and % -1 == 0. ok matthew deraadt --- bin/expr/expr.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'bin/expr/expr.c') diff --git a/bin/expr/expr.c b/bin/expr/expr.c index 615a69ed86d..085ed7114d3 100644 --- a/bin/expr/expr.c +++ b/bin/expr/expr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: expr.c,v 1.17 2006/06/21 18:28:24 deraadt Exp $ */ +/* $OpenBSD: expr.c,v 1.18 2013/03/28 08:40:31 nicm Exp $ */ /* $NetBSD: expr.c,v 1.3.6.1 1996/06/04 20:41:47 cgd Exp $ */ /* @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -329,9 +330,13 @@ eval4(void) errx(2, "division by zero"); } if (op == DIV) { - l->u.i /= r->u.i; + if (l->u.i != INT_MIN || r->u.i != -1) + l->u.i /= r->u.i; } else { - l->u.i %= r->u.i; + if (l->u.i != INT_MIN || r->u.i != -1) + l->u.i %= r->u.i; + else + l->u.i = 0; } } -- cgit v1.2.3