Skip to content

Commit

Permalink
expr(1): Fix overflow detection when operand is INTMAX_MIN
Browse files Browse the repository at this point in the history
PR:		227329
Submitted by:	Tobias Stoeckmann <tobias AT stoeckmann.org>
  • Loading branch information
cemeyer committed Apr 14, 2018
1 parent ef5bec9 commit 60e938b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions bin/expr/expr.y
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down

0 comments on commit 60e938b

Please sign in to comment.