hush: fix handling of heredocs starting with empty lines
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 23 Jul 2018 13:43:57 +0000 (15:43 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 23 Jul 2018 13:43:57 +0000 (15:43 +0200)
function                                             old     new   delta
parse_stream                                        2748    2759     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash_test/ash-heredoc/heredoc_empty3.right [new file with mode: 0644]
shell/ash_test/ash-heredoc/heredoc_empty3.tests [new file with mode: 0755]
shell/hush.c
shell/hush_test/hush-heredoc/heredoc_empty3.right [new file with mode: 0644]
shell/hush_test/hush-heredoc/heredoc_empty3.tests [new file with mode: 0755]

diff --git a/shell/ash_test/ash-heredoc/heredoc_empty3.right b/shell/ash_test/ash-heredoc/heredoc_empty3.right
new file mode 100644 (file)
index 0000000..0b54a9c
--- /dev/null
@@ -0,0 +1,2 @@
+
+Ok
diff --git a/shell/ash_test/ash-heredoc/heredoc_empty3.tests b/shell/ash_test/ash-heredoc/heredoc_empty3.tests
new file mode 100755 (executable)
index 0000000..828c2dd
--- /dev/null
@@ -0,0 +1,4 @@
+cat <<EOF
+
+Ok
+EOF
index 4fdd15900c90faedd842118335659f7cbc1ee61c..89e06df4db0eb3fa6eed4c01236988b8676b3f12 100644 (file)
@@ -4226,6 +4226,14 @@ static char *fetch_till_str(o_string *as_string,
        int prev = 0; /* not \ */
        int ch;
 
+       /* Starting with "" is necessary for this case:
+        * cat <<EOF
+        *
+        * xxx
+        * EOF
+        */
+       heredoc.data = xzalloc(1); /* start as "", not as NULL */
+
        goto jump_in;
 
        while (1) {
diff --git a/shell/hush_test/hush-heredoc/heredoc_empty3.right b/shell/hush_test/hush-heredoc/heredoc_empty3.right
new file mode 100644 (file)
index 0000000..0b54a9c
--- /dev/null
@@ -0,0 +1,2 @@
+
+Ok
diff --git a/shell/hush_test/hush-heredoc/heredoc_empty3.tests b/shell/hush_test/hush-heredoc/heredoc_empty3.tests
new file mode 100755 (executable)
index 0000000..828c2dd
--- /dev/null
@@ -0,0 +1,4 @@
+cat <<EOF
+
+Ok
+EOF