diff --git a/ChangeLog b/ChangeLog index 9f650f8..93e6240 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-01-26 Paolo Bonzini + + * sed/compile.c (check_final_program): Don't set text if the + pending_text is initialized but empty. + * sed/execute.c (output_line): Don't print text if it is NULL. + * tests/Makefile.am (TESTS): Add insert. + * tests/Makefile.tests (insert): New. + * tests/insert.good, tests/insert.sed, tests/insert.inp: New + testcase from Jonas Koelker. + 2006-12-29 Paolo Bonzini * sed/compile.c: Fix warnings. diff --git a/sed/compile.c b/sed/compile.c index 20a0523..d123f41 100644 --- a/sed/compile.c +++ b/sed/compile.c @@ -1621,8 +1621,9 @@ check_final_program(program) if (pending_text) { old_text_buf->text_length = size_buffer(pending_text); - old_text_buf->text = MEMDUP(get_buffer(pending_text), - old_text_buf->text_length, char); + if (old_text_buf->text_length) + old_text_buf->text = MEMDUP(get_buffer(pending_text), + old_text_buf->text_length, char); free_buffer(pending_text); pending_text = NULL; } diff --git a/sed/execute.c b/sed/execute.c index 10c78f3..a927dd4 100644 --- a/sed/execute.c +++ b/sed/execute.c @@ -559,11 +559,12 @@ output_line(text, length, nl, outf) bool nl; struct output *outf; { - output_missing_newline(outf); + if (!text) + return; + output_missing_newline(outf); if (length) ck_fwrite(text, 1, length, outf->fp); - if (nl) ck_fwrite("\n", 1, 1, outf->fp); else diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index d578733..09e4b87 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -22,7 +22,7 @@ SEDTESTS += \ head madding mac-mf empty xbxcx xbxcx3 recall recall2 xemacs \ fasts uniq manis khadafy linecnt eval distrib 8to7 y-bracket \ y-newline allsub cv-vars classes middle bsd stdin flipcase \ - insens subwrite writeout readin \ + insens subwrite writeout readin insert \ help version file quiet \ factor binary3 binary2 binary dc diff --git a/testsuite/Makefile.tests b/testsuite/Makefile.tests index a895cc4..fb64f2e 100644 --- a/testsuite/Makefile.tests +++ b/testsuite/Makefile.tests @@ -14,7 +14,7 @@ RM=rm -f enable sep inclib 8bit 8to7 newjis xabcx dollar noeol bkslashes \ numsub head madding mac-mf empty xbxcx xbxcx3 recall recall2 xemacs \ appquit fasts uniq manis linecnt khadafy allsub flipcase space modulo \ -y-bracket y-newline:: +y-bracket y-newline insert:: $(SEDENV) $(SED) -f $(srcdir)/$@.sed \ < $(srcdir)/$@.inp > $@.out $(CMP) $(srcdir)/$@.good $@.out diff --git a/testsuite/insert.good b/testsuite/insert.good new file mode 100644 index 0000000..5b6d250 --- /dev/null +++ b/testsuite/insert.good @@ -0,0 +1,3 @@ +bar + +foo diff --git a/testsuite/insert.inp b/testsuite/insert.inp new file mode 100644 index 0000000..1289765 --- /dev/null +++ b/testsuite/insert.inp @@ -0,0 +1,2 @@ +bar +foo diff --git a/testsuite/insert.sed b/testsuite/insert.sed new file mode 100644 index 0000000..5f7e611 --- /dev/null +++ b/testsuite/insert.sed @@ -0,0 +1 @@ +/foo/i\