Bug 227329 - [PATCH] bin/expr: do not fail with "overflow" if no overflow occurs
Summary: [PATCH] bin/expr: do not fail with "overflow" if no overflow occurs
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Conrad Meyer
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-04-06 18:53 UTC by tobias
Modified: 2018-04-14 04:35 UTC (History)
2 users (show)

See Also:


Attachments
Patch to fix the issue (488 bytes, patch)
2018-04-06 18:53 UTC, tobias
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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 2018-04-14 04:18:35 UTC
Looks correct to me.
Comment 2 Conrad Meyer freebsd_committer 2018-04-14 04:35:32 UTC
Thanks!
Comment 3 commit-hook freebsd_committer 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