svn commit: r211349 - in head: bin/sh
tools/regression/bin/sh/builtins
Jilles Tjoelker
jilles at FreeBSD.org
Sun Aug 15 21:06:54 UTC 2010
Author: jilles
Date: Sun Aug 15 21:06:53 2010
New Revision: 211349
URL: http://svn.freebsd.org/changeset/base/211349
Log:
sh: Fix break/continue/return sometimes not skipping the rest of dot script.
In our implementation and most others, a break or continue in a dot script
can break or continue a loop outside the dot script. This should cause all
further commands in the dot script to be skipped. However, cmdloop() did not
know about this and continued to parse and execute commands from the dot
script.
As described in the man page, a return in a dot script in a function returns
from the function, not only from the dot script. There was a similar issue
as with break and continue. In various other shells, the return appears to
return from the dot script, but POSIX seems not very clear about this.
Added:
head/tools/regression/bin/sh/builtins/break1.0 (contents, props changed)
head/tools/regression/bin/sh/builtins/return5.0 (contents, props changed)
Modified:
head/bin/sh/main.c
Modified: head/bin/sh/main.c
==============================================================================
--- head/bin/sh/main.c Sun Aug 15 20:56:13 2010 (r211348)
+++ head/bin/sh/main.c Sun Aug 15 21:06:53 2010 (r211349)
@@ -232,8 +232,9 @@ cmdloop(int top)
}
popstackmark(&smark);
setstackmark(&smark);
- if (evalskip == SKIPFILE) {
- evalskip = 0;
+ if (evalskip != 0) {
+ if (evalskip == SKIPFILE)
+ evalskip = 0;
break;
}
}
Added: head/tools/regression/bin/sh/builtins/break1.0
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/break1.0 Sun Aug 15 21:06:53 2010 (r211349)
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+if [ "$1" != nested ]; then
+ while :; do
+ set -- nested
+ . "$0"
+ echo bad2
+ exit 2
+ done
+ exit 0
+fi
+# To trigger the bug, the following commands must be at the top level,
+# with newlines in between.
+break
+echo bad1
+exit 1
Added: head/tools/regression/bin/sh/builtins/return5.0
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/return5.0 Sun Aug 15 21:06:53 2010 (r211349)
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+if [ "$1" != nested ]; then
+ f() {
+ set -- nested
+ . "$0"
+ # Allow return to return from the function or the dot script.
+ return 4
+ }
+ f
+ exit $(($? ^ 4))
+fi
+# To trigger the bug, the following commands must be at the top level,
+# with newlines in between.
+return 4
+echo bad
+exit 1
More information about the svn-src-head
mailing list