summaryrefslogtreecommitdiffstats
path: root/bin/expr/expr.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2013-03-28 08:39:54 +0000
committernicm <nicm@openbsd.org>2013-03-28 08:39:54 +0000
commiteb0048bac5daf3bb6590a674d97fd15d090ca073 (patch)
tree0b6242e8762c954776d069c224301720bfbe56ea /bin/expr/expr.c
parentDon't die with SIGFPE on LONG_MIN / -1 or % -1. Instead make LONG_MIN / (diff)
downloadwireguard-openbsd-eb0048bac5daf3bb6590a674d97fd15d090ca073.tar.xz
wireguard-openbsd-eb0048bac5daf3bb6590a674d97fd15d090ca073.zip
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/expr.c')
-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;
}
}