summary refs log tree commit diff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2014-10-06 19:45:58 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2014-10-06 19:45:58 +0800
commitebfdd97a10e34a5e70eadfc21ebfc033ef93a563 (patch)
tree3fc0164b796a104b850b40a871304e507edd3fc6
parent[BUILTIN] Exit without arguments in a trap should use status outside traps (diff)
downloaddash-ebfdd97a10e34a5e70eadfc21ebfc033ef93a563.tar.gz
dash-ebfdd97a10e34a5e70eadfc21ebfc033ef93a563.zip
[BUILTIN] Do not allow break to break across function calls
As it is if you do a multi-level break inside a function it'll
actually include loops outside of the function call.  This is
counterintuitive.

This patch changes this by saving and resetting loopnest when
entering a function.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to '')
-rw-r--r--ChangeLog1
-rw-r--r--src/eval.c4
2 files changed, 5 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index d0ec202..b70fa88 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2014-10-06  Herbert Xu <herbert@gondor.apana.org.au>
 
 	* Exit without arguments in a trap should use status outside traps.
+	* Do not allow break to break across function calls.
 
 2014-10-03  Herbert Xu <herbert@gondor.apana.org.au>
 
diff --git a/src/eval.c b/src/eval.c
index 51a900d..eb5b120 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -928,9 +928,11 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
 	struct jmploc jmploc;
 	int e;
 	int savefuncline;
+	int saveloopnest;
 
 	saveparam = shellparam;
 	savefuncline = funcline;
+	saveloopnest = loopnest;
 	savehandler = handler;
 	if ((e = setjmp(jmploc.loc))) {
 		goto funcdone;
@@ -940,6 +942,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
 	shellparam.malloc = 0;
 	func->count++;
 	funcline = func->n.ndefun.linno;
+	loopnest = 0;
 	INTON;
 	shellparam.nparam = argc - 1;
 	shellparam.p = argv + 1;
@@ -950,6 +953,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
 	poplocalvars(0);
 funcdone:
 	INTOFF;
+	loopnest = saveloopnest;
 	funcline = savefuncline;
 	freefunc(func);
 	freeparam(&shellparam);