aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-10 18:06:24 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-10 18:06:24 +0000
commit895bea23032221bcc158f447f81abacd046f87b1 (patch)
tree1a1a376d725353210d57a1855a9c50f4224eacca /shell
parent46ccdcb96eab18739509078638a0a7b2ae393684 (diff)
downloadbusybox-w32-895bea23032221bcc158f447f81abacd046f87b1.tar.gz
busybox-w32-895bea23032221bcc158f447f81abacd046f87b1.tar.bz2
busybox-w32-895bea23032221bcc158f447f81abacd046f87b1.zip
hush: fix some fallout from prev commits, add testsuite
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c33
-rw-r--r--shell/hush_test/hush-vars/empty.right3
-rwxr-xr-xshell/hush_test/hush-vars/empty.tests7
3 files changed, 31 insertions, 12 deletions
diff --git a/shell/hush.c b/shell/hush.c
index ca854c2eb..603e19fe9 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1234,11 +1234,14 @@ static void o_addqchr(o_string *o, int ch, int quote)
1234static int o_save_ptr(o_string *o, int n) 1234static int o_save_ptr(o_string *o, int n)
1235{ 1235{
1236 char **list = (char**)o->data; 1236 char **list = (char**)o->data;
1237 int string_start = ((n + 0xf) & ~0xf) * sizeof(list[0]); 1237 int string_start;
1238 int string_len = o->length - string_start; 1238 int string_len;
1239 1239
1240 if (!o->has_empty_slot) { 1240 if (!o->has_empty_slot) {
1241 string_start = ((n + 0xf) & ~0xf) * sizeof(list[0]);
1242 string_len = o->length - string_start;
1241 if (!(n & 0xf)) { /* 0, 0x10, 0x20...? */ 1243 if (!(n & 0xf)) { /* 0, 0x10, 0x20...? */
1244 //bb_error_msg("list[%d]=%d string_start=%d (growing)", n, string_len, string_start);
1242 /* list[n] points to string_start, make space for 16 more pointers */ 1245 /* list[n] points to string_start, make space for 16 more pointers */
1243 o->maxlen += 0x10 * sizeof(list[0]); 1246 o->maxlen += 0x10 * sizeof(list[0]);
1244 o->data = xrealloc(o->data, o->maxlen + 1); 1247 o->data = xrealloc(o->data, o->maxlen + 1);
@@ -1246,8 +1249,12 @@ static int o_save_ptr(o_string *o, int n)
1246 memmove(list + n + 0x10, list + n, string_len); 1249 memmove(list + n + 0x10, list + n, string_len);
1247 o->length += 0x10 * sizeof(list[0]); 1250 o->length += 0x10 * sizeof(list[0]);
1248 } 1251 }
1252 //else bb_error_msg("list[%d]=%d string_start=%d", n, string_len, string_start);
1249 } else { 1253 } else {
1250 /* We have empty slot at list[n], reuse without growth */ 1254 /* We have empty slot at list[n], reuse without growth */
1255 string_start = ((n+1 + 0xf) & ~0xf) * sizeof(list[0]); /* NB: n+1! */
1256 string_len = o->length - string_start;
1257 //bb_error_msg("list[%d]=%d string_start=%d (empty slot)", n, string_len, string_start);
1251 o->has_empty_slot = 0; 1258 o->has_empty_slot = 0;
1252 } 1259 }
1253 list[n] = (char*)string_len; 1260 list[n] = (char*)string_len;
@@ -2684,18 +2691,20 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
2684 arg = ++p; 2691 arg = ++p;
2685 } /* end of "while (SPECIAL_VAR_SYMBOL is found) ..." */ 2692 } /* end of "while (SPECIAL_VAR_SYMBOL is found) ..." */
2686 2693
2687 o_debug_list("expand_vars_to_list[a]", output, n); 2694 {
2688 o_addstr(output, arg, strlen(arg) + 1); 2695 int len = strlen(arg);
2689 o_debug_list("expand_vars_to_list[b]", output, n); 2696 if (len) {
2690//TESTME 2697 o_debug_list("expand_vars_to_list[a]", output, n);
2691 if (output->length - 1 == o_get_last_ptr(output, n)) { /* expansion is empty */ 2698 o_addstr(output, arg, len + 1);
2692 if (!(ored_ch & 0x80)) { /* all vars were not quoted... */ 2699 o_debug_list("expand_vars_to_list[b]", output, n);
2693 n--; 2700 } else if (output->length == o_get_last_ptr(output, n)) { /* expansion is empty */
2694 /* allow to reuse list[n] later without re-growth */ 2701 if (!(ored_ch & 0x80)) { /* all vars were not quoted... */
2695 output->has_empty_slot = 1; 2702 n--;
2703 /* allow to reuse list[n] later without re-growth */
2704 output->has_empty_slot = 1;
2705 }
2696 } 2706 }
2697 } 2707 }
2698
2699 return n; 2708 return n;
2700} 2709}
2701 2710
diff --git a/shell/hush_test/hush-vars/empty.right b/shell/hush_test/hush-vars/empty.right
new file mode 100644
index 000000000..2cb3c70f2
--- /dev/null
+++ b/shell/hush_test/hush-vars/empty.right
@@ -0,0 +1,3 @@
1a b c d e f 1 2 3 4 5 6 7 8 9 0 A B C D E F
2a b c d e f 1 2 3 4 5 6 7 8 9 0 A B C D E F
3a b c d e f 1 2 3 4 5 6 7 8 9 0 A B C D E F
diff --git a/shell/hush_test/hush-vars/empty.tests b/shell/hush_test/hush-vars/empty.tests
new file mode 100755
index 000000000..72ac2c743
--- /dev/null
+++ b/shell/hush_test/hush-vars/empty.tests
@@ -0,0 +1,7 @@
1#!/bin/sh
2
3e=
4
5echo a b c d e f 1 2 3 4 5 6 7 8 9 0 A B C D E F
6echo a $e b $e c $e d $e e $e f $e 1 $e 2 $e 3 $e 4 $e 5 $e 6 $e 7 $e 8 $e 9 $e 0 $e A $e B $e C $e D $e E $e F
7echo $e a $e b $e c $e d $e e $e f $e 1 $e 2 $e 3 $e 4 $e 5 $e 6 $e 7 $e 8 $e 9 $e 0 $e A $e B $e C $e D $e E $e F