mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-19 11:31:26 +01:00
32479: POSIXTRAPS and implicit return values.
With POSIXTRAPS never propagate implicit return value. In any case if not forcing a return value don't use lastval from within the trap, use the one from the surrounding code.
This commit is contained in:
parent
89c2342dd8
commit
a06cd1766a
3 changed files with 22 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
2014-03-14 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* 32479: Src/builtin.c, Src/signals.c: with POSIXTRAPS
|
||||
never propagate an implicit return from within a trap.
|
||||
|
||||
2014-03-13 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||
|
||||
* Kosuke Asami: 32473: Completion/Unix/Command/_pgrep: tidy up
|
||||
|
|
|
@ -4688,9 +4688,10 @@ exit_pending;
|
|||
int
|
||||
bin_break(char *name, char **argv, UNUSED(Options ops), int func)
|
||||
{
|
||||
int num = lastval, nump = 0;
|
||||
int num = lastval, nump = 0, implicit;
|
||||
|
||||
/* handle one optional numeric argument */
|
||||
implicit = !*argv;
|
||||
if (*argv) {
|
||||
num = mathevali(*argv++);
|
||||
nump = 1;
|
||||
|
@ -4721,7 +4722,13 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func)
|
|||
retflag = 1;
|
||||
breaks = loops;
|
||||
lastval = num;
|
||||
if (trap_state == TRAP_STATE_PRIMED && trap_return == -2) {
|
||||
if (trap_state == TRAP_STATE_PRIMED && trap_return == -2
|
||||
/*
|
||||
* With POSIX, "return" on its own in a trap doesn't
|
||||
* update $? --- we keep the status from before the
|
||||
* trap.
|
||||
*/
|
||||
&& !(isset(POSIXTRAPS) && implicit)) {
|
||||
trap_state = TRAP_STATE_FORCE_RETURN;
|
||||
trap_return = lastval;
|
||||
}
|
||||
|
|
|
@ -1155,6 +1155,7 @@ dotrapargs(int sig, int *sigtr, void *sigfn)
|
|||
char *name, num[4];
|
||||
int obreaks = breaks;
|
||||
int oretflag = retflag;
|
||||
int olastval = lastval;
|
||||
int isfunc;
|
||||
int traperr, new_trap_state, new_trap_return;
|
||||
|
||||
|
@ -1261,6 +1262,13 @@ dotrapargs(int sig, int *sigtr, void *sigfn)
|
|||
} else {
|
||||
if (traperr && !EMULATION(EMULATE_SH))
|
||||
lastval = 1;
|
||||
else {
|
||||
/*
|
||||
* With no explicit forced return, we keep the
|
||||
* lastval from before the trap ran.
|
||||
*/
|
||||
lastval = olastval;
|
||||
}
|
||||
if (try_tryflag)
|
||||
errflag = traperr;
|
||||
breaks += obreaks;
|
||||
|
|
Loading…
Reference in a new issue