summary refs log tree commit diff
path: root/src/var.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2010-05-27 11:32:55 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2010-05-27 11:32:55 +0800
commit127788364951212c356aadc39deb21e01b0161c8 (patch)
treeac64558fdf474a76008c7c924114a6a3c5a9f144 /src/var.c
parent[VAR] Replace cmdenviron with localvars (diff)
downloaddash-127788364951212c356aadc39deb21e01b0161c8.tar.gz
dash-127788364951212c356aadc39deb21e01b0161c8.zip
[VAR] Fix poplocalvar on abnormal exit from function
The new localvar code broke the abnormal exit from functions
and built-ins by not restoring the original localvar state.

This patch fixes this by storing the previous localvar state so
that we always unwind correctly in case of an abnormal exit.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'src/var.c')
-rw-r--r--src/var.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/var.c b/src/var.c
index 40bd3fd..f456fbd 100644
--- a/src/var.c
+++ b/src/var.c
@@ -144,8 +144,7 @@ INIT {
 }
 
 RESET {
-	while (localvar_stack)
-		poplocalvars(0);
+	unwindlocalvars(0);
 }
 #endif
 
@@ -570,7 +569,7 @@ poplocalvars(int keep)
 /*
  * Create a new localvar environment.
  */
-void pushlocalvars(void)
+struct localvar_list *pushlocalvars(void)
 {
 	struct localvar_list *ll;
 
@@ -580,6 +579,15 @@ void pushlocalvars(void)
 	ll->next = localvar_stack;
 	localvar_stack = ll;
 	INTON;
+
+	return ll->next;
+}
+
+
+void unwindlocalvars(struct localvar_list *stop)
+{
+	while (localvar_stack != stop)
+		poplocalvars(0);
 }
 
 
.agency/Makefile?id=c31cba908c3b810905b0363be3d6738a2868a03c&follow=1'>Publish "Using vi"June McEnroe 2021-01-11Enable diff.colorMovedJune McEnroe 2021-01-10Set less search case-insensitiveJune McEnroe 2021-01-10Set EXINITJune McEnroe 2021-01-09Add c -t flag to print expression typeJune McEnroe 2021-01-05Update taglineJune McEnroe