summaryrefslogtreecommitdiff
path: root/Src/loop.c
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2014-12-27 21:55:58 -0800
committerBarton E. Schaefer <schaefer@zsh.org>2014-12-27 21:55:58 -0800
commitd6a32ddeed914434f5b56b013c9d03b28781d065 (patch)
tree050eb544d08c31b8ad2d443a7563bf68b6b72355 /Src/loop.c
parent89c692eafb78d4f5a7cf48dc8fc8ab3e5eb73abd (diff)
downloadzsh-d6a32ddeed914434f5b56b013c9d03b28781d065.tar.gz
zsh-d6a32ddeed914434f5b56b013c9d03b28781d065.zip
34065: following an "if" condition, do not test lastval for ERR_EXIT until a new command is run
Includes unposted regression tests.
Diffstat (limited to 'Src/loop.c')
-rw-r--r--Src/loop.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/Src/loop.c b/Src/loop.c
index 8bb1ec9dd..7b3bdd2c8 100644
--- a/Src/loop.c
+++ b/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;