From owner-svn-src-all@freebsd.org  Sat Apr 14 04:35:11 2018
Return-Path: <owner-svn-src-all@freebsd.org>
Delivered-To: svn-src-all@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 438AFFA2411;
 Sat, 14 Apr 2018 04:35:11 +0000 (UTC) (envelope-from cem@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org
 [IPv6:2610:1c1:1:606c::19:3])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client CN "mxrelay.nyi.freebsd.org",
 Issuer "Let's Encrypt Authority X3" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id EAC658785F;
 Sat, 14 Apr 2018 04:35:10 +0000 (UTC) (envelope-from cem@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2610:1c1:1:6068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E5D1A238F7;
 Sat, 14 Apr 2018 04:35:10 +0000 (UTC) (envelope-from cem@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3E4ZApx098698;
 Sat, 14 Apr 2018 04:35:10 GMT (envelope-from cem@FreeBSD.org)
Received: (from cem@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3E4ZAiI098697;
 Sat, 14 Apr 2018 04:35:10 GMT (envelope-from cem@FreeBSD.org)
Message-Id: <201804140435.w3E4ZAiI098697@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org
 using -f
From: Conrad Meyer <cem@FreeBSD.org>
Date: Sat, 14 Apr 2018 04:35:10 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-head@freebsd.org
Subject: svn commit: r332499 - head/bin/expr
X-SVN-Group: head
X-SVN-Commit-Author: cem
X-SVN-Commit-Paths: head/bin/expr
X-SVN-Commit-Revision: 332499
X-SVN-Commit-Repository: base
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-all@freebsd.org
X-Mailman-Version: 2.1.25
Precedence: list
List-Id: "SVN commit messages for the entire src tree \(except for &quot;
 user&quot; and &quot; projects&quot; \)" <svn-src-all.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-all>,
 <mailto:svn-src-all-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-all/>
List-Post: <mailto:svn-src-all@freebsd.org>
List-Help: <mailto:svn-src-all-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-all>,
 <mailto:svn-src-all-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sat, 14 Apr 2018 04:35:11 -0000

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 *