Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Apr 2018 04:35:10 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r332499 - head/bin/expr
Message-ID:  <201804140435.w3E4ZAiI098697@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Sat Apr 14 04:35:10 2018
New Revision: 332499
URL: https://svnweb.freebsd.org/changeset/base/332499

Log:
  expr(1): Fix overflow detection when operand is INTMAX_MIN
  
  PR:		227329
  Submitted by:	Tobias Stoeckmann <tobias AT stoeckmann.org>

Modified:
  head/bin/expr/expr.y

Modified: head/bin/expr/expr.y
==============================================================================
--- head/bin/expr/expr.y	Sat Apr 14 03:15:05 2018	(r332498)
+++ head/bin/expr/expr.y	Sat Apr 14 04:35:10 2018	(r332499)
@@ -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 *



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201804140435.w3E4ZAiI098697>