Bug 227329

Summary: [PATCH] bin/expr: do not fail with "overflow" if no overflow occurs
Product: Base System Reporter: tobias
Component: binAssignee: Conrad Meyer <cem>
Status: Closed FIXED    
Severity: Affects Only Me CC: cem, emaste
Priority: --- Keywords: patch
Version: CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Patch to fix the issue none

Description tobias 2018-04-06 18:53:41 UTC
Created attachment 192294 [details]
Patch to fix the issue

It is possible to trigger an overflow error message with expr, even though no overflow would occur:

$ expr -- -36854775800 - \( -9223372036854775807 - 1 \)
expr: overflow
$ _

The function assert_minus() verifies subtraction in an invert addition case, which is not correct.

See also the OpenBSD discussion here: https://marc.info/?l=openbsd-tech&m=152245790622327&w=2
Comment 1 Conrad Meyer freebsd_committer freebsd_triage 2018-04-14 04:18:35 UTC
Looks correct to me.
Comment 2 Conrad Meyer freebsd_committer freebsd_triage 2018-04-14 04:35:32 UTC
Thanks!
Comment 3 commit-hook freebsd_committer freebsd_triage 2018-04-14 04:35:43 UTC
A commit references this bug:

Author: cem
Date: Sat Apr 14 04:35:10 UTC 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>

Changes:
  head/bin/expr/expr.y