Skip to content

expr: fix eager evaluation of parenthesized dead branches#11395

Merged
sylvestre merged 2 commits intouutils:mainfrom
can1357:expr-fix-eager-evaluation-of-parenthesized-dead-branches
Apr 3, 2026
Merged

expr: fix eager evaluation of parenthesized dead branches#11395
sylvestre merged 2 commits intouutils:mainfrom
can1357:expr-fix-eager-evaluation-of-parenthesized-dead-branches

Conversation

@can1357
Copy link
Copy Markdown
Contributor

@can1357 can1357 commented Mar 18, 2026

uutils expr evaluates parenthesized subexpressions during parsing, so arithmetic errors in dead | and & branches are raised before short-circuiting. GNU parses those branches without forcing evaluation and only evaluates when the branch is actually needed.

Reproduction Steps

expr 1 '|' '(' 1 / 0 ')'
# Expected (GNU): exit 0, stdout "1", no stderr
# Actual (uutils): exit 2, stderr "expr: division by zero"

Impact

Guarded expressions can fail with hard errors instead of boolean results, which breaks GNU-compatible shell control flow and error handling.

sylvestre added a commit to sylvestre/coreutils-1 that referenced this pull request Apr 3, 2026
* tests/expr/expr.pl: Add tests to verify that short-circuit
evaluation of | and & correctly skips parenthesized dead branches,
including nested parenthesized expressions containing division by zero.
uutils/coreutils#11395
@sylvestre sylvestre merged commit 76b2f78 into uutils:main Apr 3, 2026
163 checks passed
gitmirroring-auto-sync-bot bot pushed a commit to GitMirroring/coreutils that referenced this pull request Apr 6, 2026
* tests/expr/expr.pl: Add tests to verify that short-circuit
evaluation of | and & correctly skips parenthesized dead branches,
including nested parenthesized expressions containing division by zero.
uutils/coreutils#11395
coreutils/coreutils#238
kevinburkesegment pushed a commit to kevinburkesegment/coreutils that referenced this pull request Apr 6, 2026
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants