aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2018-04-14 04:35:10 +0000
committerConrad Meyer <cem@FreeBSD.org>2018-04-14 04:35:10 +0000
commit41bd31e656e776866ce3f6d64923913b3cf4a712 (patch)
tree8ef81a41080a5c12b6bcb794c48743741888a241 /bin
parentf6e61711eddfa193d1c3e8a1ffd53c6395e9b8c8 (diff)
downloadsrc-41bd31e656e776866ce3f6d64923913b3cf4a712.tar.gz
src-41bd31e656e776866ce3f6d64923913b3cf4a712.zip
expr(1): Fix overflow detection when operand is INTMAX_MIN
PR: 227329 Submitted by: Tobias Stoeckmann <tobias AT stoeckmann.org>
Notes
Notes: svn path=/head/; revision=332499
Diffstat (limited to 'bin')
-rw-r--r--bin/expr/expr.y6
1 files changed, 2 insertions, 4 deletions
diff --git a/bin/expr/expr.y b/bin/expr/expr.y
index 0ddf3990d2a8..4f07275031a3 100644
--- a/bin/expr/expr.y
+++ b/bin/expr/expr.y
@@ -422,11 +422,9 @@ op_plus(struct val *a, struct val *b)
void
assert_minus(intmax_t a, intmax_t b, intmax_t r)
{
- /* special case subtraction of INTMAX_MIN */
- if (b == INTMAX_MIN && a < 0)
+ if ((a >= 0 && b < 0 && r <= 0) ||
+ (a < 0 && b > 0 && r >= 0))
errx(ERR_EXIT, "overflow");
- /* check addition of negative subtrahend */
- assert_plus(a, -b, r);
}
struct val *