svn commit: trunk/busybox/shell: hush_test/hush-bugs hush_test/hush-misc

vda at busybox.net vda at busybox.net
Tue Jun 17 12:09:23 UTC 2008


Author: vda
Date: 2008-06-17 05:09:21 -0700 (Tue, 17 Jun 2008)
New Revision: 22395

Log:
hush: fix "for a in; do echo 'I should never run'; done" bug



Added:
   trunk/busybox/shell/hush_test/hush-misc/empty_for.right
   trunk/busybox/shell/hush_test/hush-misc/empty_for.tests

Removed:
   trunk/busybox/shell/hush_test/hush-bugs/empty_for.right
   trunk/busybox/shell/hush_test/hush-bugs/empty_for.tests

Modified:
   trunk/busybox/shell/hush.c


Changeset:
Modified: trunk/busybox/shell/hush.c
===================================================================
--- trunk/busybox/shell/hush.c	2008-06-17 08:04:15 UTC (rev 22394)
+++ trunk/busybox/shell/hush.c	2008-06-17 12:09:21 UTC (rev 22395)
@@ -2004,7 +2004,7 @@
 		 || (rpipe->res_word == RES_FOR && rpipe->next->res_word != RES_IN)
 		) {
 			/* TODO: what is tested in the first condition? */
-			syntax("malformed for"); /* 2nd condition: not followed by IN */
+			syntax("malformed for"); /* 2nd condition: FOR not followed by IN */
 			debug_printf_exec("run_list lvl %d return 1\n", run_list_level);
 			return 1;
 		}
@@ -2898,7 +2898,8 @@
 		ctx->pending_redirect = NULL;
 	}
 #if ENABLE_HUSH_LOOPS
-	if (ctx->res_w == RES_FOR) { /* comment? */
+	/* comment? is it forcing "for" to have just one word (variable name)? */
+	if (ctx->res_w == RES_FOR) {
 //TESTING
 //looks like (word->length == 0 && !word->nonnull) is true here, always
 //(due to o_reset). done_word would return at once. Why then?
@@ -2910,8 +2911,8 @@
 	return 0;
 }
 
-/* The only possible error here is out of memory, in which case
- * xmalloc exits. */
+/* Command (member of a pipe) is complete. The only possible error here
+ * is out of memory, in which case xmalloc exits. */
 static int done_command(struct p_context *ctx)
 {
 	/* The child is really already in the pipe structure, so
@@ -2949,7 +2950,6 @@
 
 static void done_pipe(struct p_context *ctx, pipe_style type)
 {
-	struct pipe *new_p;
 	int not_null;
 
 	debug_printf_parse("done_pipe entered, followup %d\n", type);
@@ -2960,9 +2960,11 @@
 	ctx->ctx_inverted = 0;
 	/* Without this check, even just <enter> on command line generates
 	 * tree of three NOPs (!). Which is harmless but annoying.
-	 * IOW: it is safe to do it unconditionally. */
-	if (not_null) {
-		new_p = new_pipe();
+	 * IOW: it is safe to do it unconditionally.
+	 * RES_IN case is for "for a in; do ..." (empty IN set)
+	 * to work. */
+	if (not_null || ctx->pipe->res_word == RES_IN) {
+		struct pipe *new_p = new_pipe();
 		ctx->pipe->next = new_p;
 		ctx->pipe = new_p;
 		ctx->child = NULL; /* needed! */

Deleted: trunk/busybox/shell/hush_test/hush-bugs/empty_for.right
===================================================================
--- trunk/busybox/shell/hush_test/hush-bugs/empty_for.right	2008-06-17 08:04:15 UTC (rev 22394)
+++ trunk/busybox/shell/hush_test/hush-bugs/empty_for.right	2008-06-17 12:09:21 UTC (rev 22395)
@@ -1 +0,0 @@
-OK: 0

Deleted: trunk/busybox/shell/hush_test/hush-bugs/empty_for.tests
===================================================================
--- trunk/busybox/shell/hush_test/hush-bugs/empty_for.tests	2008-06-17 08:04:15 UTC (rev 22394)
+++ trunk/busybox/shell/hush_test/hush-bugs/empty_for.tests	2008-06-17 12:09:21 UTC (rev 22395)
@@ -1,3 +0,0 @@
-false
-for a in; do echo "HELLO"; done
-echo OK: $?

Copied: trunk/busybox/shell/hush_test/hush-misc/empty_for.right (from rev 22380, trunk/busybox/shell/hush_test/hush-bugs/empty_for.right)
===================================================================
--- trunk/busybox/shell/hush_test/hush-misc/empty_for.right	                        (rev 0)
+++ trunk/busybox/shell/hush_test/hush-misc/empty_for.right	2008-06-17 12:09:21 UTC (rev 22395)
@@ -0,0 +1 @@
+OK: 0

Copied: trunk/busybox/shell/hush_test/hush-misc/empty_for.tests (from rev 22380, trunk/busybox/shell/hush_test/hush-bugs/empty_for.tests)
===================================================================
--- trunk/busybox/shell/hush_test/hush-misc/empty_for.tests	                        (rev 0)
+++ trunk/busybox/shell/hush_test/hush-misc/empty_for.tests	2008-06-17 12:09:21 UTC (rev 22395)
@@ -0,0 +1,3 @@
+false
+for a in; do echo "HELLO"; done
+echo OK: $?




More information about the busybox-cvs mailing list