summaryrefslogtreecommitdiff
path: root/Src/builtin.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2014-03-14 12:52:41 +0000
committerPeter Stephenson <pws@zsh.org>2014-03-14 12:52:41 +0000
commita06cd1766afdbb74ec97e650f0bd945a78a8fdc8 (patch)
treedefd7cb3c1f3287d68873b9b787dfd5572b83e3c /Src/builtin.c
parent89c2342dd8d1bfb8e907b397a83e273553f1ad62 (diff)
downloadzsh-a06cd1766afdbb74ec97e650f0bd945a78a8fdc8.tar.gz
zsh-a06cd1766afdbb74ec97e650f0bd945a78a8fdc8.zip
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.
Diffstat (limited to 'Src/builtin.c')
-rw-r--r--Src/builtin.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 9bcbcf707..0cc54b7bb 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -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;
}