summaryrefslogtreecommitdiff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2015-05-13 16:17:04 +0100
committerPeter Stephenson <pws@zsh.org>2015-05-13 16:17:04 +0100
commitec57c91b586a7682fcdb08c3704c9214cddfa5e7 (patch)
tree6baa5dd3f864f4ddec5496c29913a13e7a00f16f /Src
parent9c3aeef99a64c44e5a37170c9440c591f223bb4a (diff)
downloadzsh-ec57c91b586a7682fcdb08c3704c9214cddfa5e7.tar.gz
zsh-ec57c91b586a7682fcdb08c3704c9214cddfa5e7.zip
users/20203: nested functions in always blocks when exit pending
Diffstat (limited to 'Src')
-rw-r--r--Src/builtin.c6
-rw-r--r--Src/exec.c10
2 files changed, 15 insertions, 1 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index ffde5c916..70e75ff17 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4788,6 +4788,11 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun
mod_export int
exit_pending;
+/* Shell level at which we exit if exit_pending */
+/**/
+mod_export int
+exit_level;
+
/* break, bye, continue, exit, logout, return -- most of these take *
* one numeric argument, and the other (logout) is related to return. *
* (return is treated as a logout when in a login shell.) */
@@ -4865,6 +4870,7 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func)
retflag = 1;
breaks = loops;
exit_pending = (num << 1) | 1;
+ exit_level = locallevel;
}
} else
zexit(num, 0);
diff --git a/Src/exec.c b/Src/exec.c
index 6a8b35a36..527dffba8 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -5101,7 +5101,15 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
}
popheap();
- if (exit_pending) {
+ /*
+ * Exit with a tidy up.
+ * Only leave if we're at the end of the appropriate function ---
+ * not a nested function. As we usually skip the function body,
+ * the only likely case where we need that second test is
+ * when we have an "always" block. The endparamscope() has
+ * already happened, hence the "+1" here.
+ */
+ if (exit_pending && exit_level == locallevel+1) {
if (locallevel > forklevel) {
/* Still functions to return: force them to do so. */
retflag = 1;