mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix BUG_LOOPRET2 and related return/exit misbehaviour
The 'exit' and 'return' commands without an argument failed to pass down the exit status of the last-run command when incorporated in a block with redirection, &&/|| list, 'case' statement, or 'while', 'until' or 'for' loop. src/cmd/ksh93/bltins/cflow.c: - Use $?, which is sh.savexit a.k.a. shp->savexit, as the default exit status value if there is no argument, instead of shp->oldexit. This fixes the default exit status behaviour to match POSIX and other shells. src/cmd/ksh93/include/defs.h, src/cmd/ksh93/include/shell.h: - Remove now-unused sh.oldexit (a.k.a. shp->oldexit) private struct member. It appeared to fulfill the same function as sh.savexit, but in a slightly broken way. - Move the savexit/$? declaration from the _SH_PRIVATE part of the struct definition to the public API part. Since $? uses this, it's clearly a publicly exposed value already, and this is generally the one to use. (If anything, it's exitval that should have been private.) This declares savexit right next to exitval, rewriting the comments to clarify the difference between them. src/cmd/ksh93/sh/fault.c, src/cmd/ksh93/sh/subshell.c, src/cmd/ksh93/sh/xec.c: - Remove assignments to shp->oldexit. src/cmd/ksh93/tests/basic.sh: - Add thorough regression tests for the default exit status behaviour of 'return' and 'exit' in various lexical contexts. - Verify that 'for' and 'case' without any command, as well as a lone redirection, still correctly reset the exit status to 0. Fixes: #117
This commit is contained in:
parent
400c107773
commit
092b90da81
10 changed files with 98 additions and 15 deletions
12
NEWS
12
NEWS
|
@ -3,6 +3,18 @@ For full details, see the git log at: https://github.com/ksh93/ksh
|
|||
|
||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||
|
||||
2020-09-09:
|
||||
|
||||
- Fixed BUG_LOOPRET2 and related bugs. The 'exit' and 'return' commands without
|
||||
an argument now correctly default to passing down the exit status of the
|
||||
last-run command. Tests like the following, in which the last-run command is
|
||||
'false', now correctly output 1 instead of 0:
|
||||
fn() { return || true; }; false; fn; echo "$?"
|
||||
fn() { while return; do true; done; }; false; fn; echo "$?"
|
||||
fn() { for i in 1; do return; done; }; false; fn; echo "$?"
|
||||
fn() { case 1 in 1) return ;; esac; }; false; fn; echo "$?"
|
||||
fn() { { return; } 2>&1; }; false; fn; echo "$?"
|
||||
|
||||
2020-09-05:
|
||||
|
||||
- Fixed erroneous syntax errors in parameter expansions such as ${var:-wor)d}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue