mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-11-15 13:34:18 +01:00
34065: following an "if" condition, do not test lastval for ERR_EXIT until a new command is run
Includes unposted regression tests.
This commit is contained in:
parent
89c692eafb
commit
d6a32ddeed
@ -1,3 +1,10 @@
|
||||
2014-12-27 Barton E. Schaefer <schaefer@zsh.org>
|
||||
|
||||
* unposted: Test/A05execution.ztst: regressions for 34065
|
||||
|
||||
* 34065: Src/exec.c, Src/loop.c: following an "if" condition, do
|
||||
not test lastval for ERR_EXIT until a new command is run
|
||||
|
||||
2014-12-21 Oliver Kiddle <opk@zsh.org>
|
||||
|
||||
* Daniel Shahaf: 33977: Completion/Zsh/Command/_bindkey:
|
||||
|
@ -2632,6 +2632,10 @@ execcmd(Estate state, int input, int output, int how, int last1)
|
||||
}
|
||||
}
|
||||
|
||||
/* if we get this far, it is OK to pay attention to lastval again */
|
||||
if (noerrexit == 2 && !is_shfunc)
|
||||
noerrexit = 0;
|
||||
|
||||
/* Do prefork substitutions */
|
||||
esprefork = (assign || isset(MAGICEQUALSUBST)) ? PREFORK_TYPESET : 0;
|
||||
if (args && htok)
|
||||
|
16
Src/loop.c
16
Src/loop.c
@ -102,7 +102,10 @@ execfor(Estate state, int do_exec)
|
||||
addlinknode(args, dupstring(*x));
|
||||
}
|
||||
}
|
||||
/* lastval = 0; */
|
||||
|
||||
if (!args || empty(args))
|
||||
lastval = 0;
|
||||
|
||||
loops++;
|
||||
pushheap();
|
||||
cmdpush(CS_FOR);
|
||||
@ -238,10 +241,10 @@ execselect(Estate state, UNUSED(int do_exec))
|
||||
}
|
||||
if (!args || empty(args)) {
|
||||
state->pc = end;
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
loops++;
|
||||
/* lastval = 0; */
|
||||
|
||||
pushheap();
|
||||
cmdpush(CS_SELECT);
|
||||
usezle = interact && SHTTY != -1 && isset(USEZLE);
|
||||
@ -519,14 +522,17 @@ execif(Estate state, int do_exec)
|
||||
s = 1;
|
||||
state->pc = next;
|
||||
}
|
||||
noerrexit = olderrexit;
|
||||
|
||||
if (run) {
|
||||
/* we need to ignore lastval until we reach execcmd() */
|
||||
noerrexit = olderrexit ? olderrexit : lastval ? 2 : 0;
|
||||
cmdpush(run == 2 ? CS_ELSE : (s ? CS_ELIFTHEN : CS_IFTHEN));
|
||||
execlist(state, 1, do_exec);
|
||||
cmdpop();
|
||||
} else
|
||||
} else {
|
||||
noerrexit = olderrexit;
|
||||
lastval = 0;
|
||||
}
|
||||
state->pc = end;
|
||||
|
||||
return lastval;
|
||||
|
@ -269,3 +269,20 @@ F:anonymous function, and a descriptor leak when backgrounding a pipeline
|
||||
1:The status of recently exited background jobs is recorded
|
||||
>3
|
||||
>2
|
||||
|
||||
# Regression test for workers/34060 (patch in 34065)
|
||||
setopt ERR_EXIT NULL_GLOB
|
||||
if false; then :; else echo if:$?; fi
|
||||
if false; then :; else for x in _*_; do :; done; echo for:$?; fi
|
||||
0:False "if" condition handled correctly by "for" loops with ERR_EXIT
|
||||
>if:1
|
||||
>for:0
|
||||
|
||||
# Regression test for workers/34065 (uses setopt from preceding test)
|
||||
select x; do :; done; echo $?
|
||||
select x in; do :; done; echo $?
|
||||
select x in _*_; do :; done; echo $?
|
||||
0:The status of "select" is zero when the loop body does not execute
|
||||
>0
|
||||
>0
|
||||
>0
|
||||
|
Loading…
Reference in New Issue
Block a user