Fix a simple mistake with pattern space, and add a test for it
authorGlenn L McGrath <bug1@ihug.co.nz>
Mon, 15 Sep 2003 12:07:48 +0000 (12:07 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Mon, 15 Sep 2003 12:07:48 +0000 (12:07 -0000)
editors/sed.c
testsuite/sed/sed-append-hold-space-to-pattern-space [new file with mode: 0644]

index 05eb744..da15c4d 100644 (file)
@@ -1070,9 +1070,9 @@ static void process_file(FILE * file)
                                        }
                                        pattern_space = xrealloc(pattern_space, pattern_space_size + hold_space_size);
                                        if (pattern_space_size == 2) {
-                                               strcat(pattern_space, "\n");
-                                       } else {
                                                strcpy(pattern_space, "\n");
+                                       } else {
+                                               strcat(pattern_space, "\n");
                                        }
                                        if (hold_space) {
                                                strcat(pattern_space, hold_space);
diff --git a/testsuite/sed/sed-append-hold-space-to-pattern-space b/testsuite/sed/sed-append-hold-space-to-pattern-space
new file mode 100644 (file)
index 0000000..6dda80f
--- /dev/null
@@ -0,0 +1,13 @@
+busybox sed 'G'>output <<EOF
+a
+b
+c
+EOF
+cmp -s output - <<EOF
+a
+
+b
+
+c
+
+EOF