expr(1): Fix overflow detection when operand is INTMAX_MIN

PR:		227329
Submitted by:	Tobias Stoeckmann <tobias AT stoeckmann.org>
This commit is contained in:
cem 2018-04-14 04:35:10 +00:00
parent ef5bec98f2
commit 60e938ba62

View File

@ -422,11 +422,9 @@ op_plus(struct val *a, struct val *b)
void void
assert_minus(intmax_t a, intmax_t b, intmax_t r) assert_minus(intmax_t a, intmax_t b, intmax_t r)
{ {
/* special case subtraction of INTMAX_MIN */ if ((a >= 0 && b < 0 && r <= 0) ||
if (b == INTMAX_MIN && a < 0) (a < 0 && b > 0 && r >= 0))
errx(ERR_EXIT, "overflow"); errx(ERR_EXIT, "overflow");
/* check addition of negative subtrahend */
assert_plus(a, -b, r);
} }
struct val * struct val *