From d24d7242fecec5a6d9db6f27f7439281dfa17021 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Thu, 14 Apr 2022 16:31:50 -0700 Subject: [PATCH] 50068: 'exit' in trap causes calling function to return --- Etc/BUGS | 3 --- Src/builtin.c | 2 ++ Test/C03traps.ztst | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Etc/BUGS b/Etc/BUGS index 5624fb24d..3121fc9fa 100644 --- a/Etc/BUGS +++ b/Etc/BUGS @@ -30,9 +30,6 @@ skipped when STTY=... is set for that command ------------------------------------------------------------------------ 42609: :|: =(hang) ------------------------------------------------------------------------ -44007 - Martijn - exit in trap executes rest of function -See test case in Test/C03traps.ztst. ------------------------------------------------------------------------- 44133 debian #924736 (partial patch in 44134) three setopts following ` #` ------------------------------------------------------------------------ 44850 terminal issues with continuation markers diff --git a/Src/builtin.c b/Src/builtin.c index 8ef678b22..b93466ba5 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5720,6 +5720,8 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func) * a bad job. */ if (stopmsg || (zexit(0, ZEXIT_DEFERRED), !stopmsg)) { + if (trap_state) + trap_state = TRAP_STATE_FORCE_RETURN; retflag = 1; breaks = loops; exit_pending = 1; diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst index 6f84e5db2..3bd2958cb 100644 --- a/Test/C03traps.ztst +++ b/Test/C03traps.ztst @@ -901,7 +901,7 @@ F:Must be tested with a top-level script rather than source or function fn trap1 trap2 echo out2 ' --f:(workers/44007) function execution continues after 'exit' in trap +-:(workers/44007) function execution continues after 'exit' in trap >out1 >fn1 >trap1