summaryrefslogtreecommitdiff
path: root/bin/expr
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2013-03-28 08:40:32 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2013-03-28 08:40:32 +0000
commitdaa12e324da3d06e02e5e85bc27d5855273f2617 (patch)
treef9fb928dc66ec9da945f977da2ea6cc52e9c54bd /bin/expr
parentc49d8bff47e84ad42aa42109dd5b7968bc27766a (diff)
Don't die with SIGFPE on INT_MIN / -1 or % -1. Instead make INT_MIN /
-1 == INT_MIN and % -1 == 0. ok matthew deraadt
Diffstat (limited to 'bin/expr')
-rw-r--r--bin/expr/expr.c11
1 files changed, 8 insertions, 3 deletions
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include <locale.h>
#include <ctype.h>
#include <regex.h>
@@ -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;
}
}