[SV #38945] Copy the entire buffer back when overwriting CR
authorPaul Smith <psmith@gnu.org>
Sun, 26 May 2013 18:41:45 +0000 (14:41 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 26 May 2013 18:41:45 +0000 (14:41 -0400)
ChangeLog
read.c
tests/ChangeLog
tests/scripts/misc/bs-nl

index ff5bec59744c14e6d935f0da26f02212f12c0a3d..498ad56f08f4619bc8ed1341d06370a223f3c9f0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2013-05-26  Paul Smith  <psmith@gnu.org>
 
+       * read.c (readline): To be safe, move the entire buffer if we
+       detect a CR.  Fixes Savannah bug #38945.
+
        * job.c (new_job): Compare OUT to the beginning of the OUT
        var/function, not IN.  Fixes Savannah bug #39035.
 
diff --git a/read.c b/read.c
index 36d3a8fa38644a7ace2023e9168d811b0b7246b7..d6e6fcb11edc2958046fcf744ec3b0b75cd70e0c 100644 (file)
--- a/read.c
+++ b/read.c
@@ -2542,7 +2542,7 @@ readline (struct ebuffer *ebuf)
       if ((p - start) > 1 && p[-2] == '\r')
         {
           --p;
-          p[-1] = '\n';
+          memmove (p-1, p, strlen (p) + 1);
         }
 #endif
 
index 1f93930f4819738992f157a27c5e7530335ee78d..7f1bd3cffe20ade443122b0ec34af575d6b1e828 100644 (file)
@@ -1,6 +1,7 @@
 2013-05-26  Paul Smith  <psmith@gnu.org>
 
        * scripts/misc/bs-nl: Test for Savannah bug #39035.
+       Add a test for Savannah bug #38945.
 
 2013-05-22  Paul Smith  <psmith@gnu.org>
 
index aa7661ea8db2194109f3a0c595a7913d4497a604..4fc3f6399688c45793bb16145a615f76c8cf2041 100644 (file)
@@ -114,10 +114,15 @@ t:; @$(call f,"a \
 my $m1 = get_tmpfile();
 open(MAKEFILE, "> $m1");
 binmode(MAKEFILE);
-print MAKEFILE "FOO = foo \\\r\nbar\nall: ; \@echo \$(FOO)\n";
+print MAKEFILE "FOO = foo \\\r\n";
 close(MAKEFILE);
 
-run_make_with_options($m1, '', get_logfile());
+my $m2 = get_tmpfile();
+open(MAKEFILE, "> $m2");
+print MAKEFILE "include $m1\ndefine BAR\nall: ; \@echo \$(FOO) bar\nendef\n\$(eval \$(BAR))\n";
+close(MAKEFILE);
+
+run_make_with_options($m2, '', get_logfile());
 compare_output("foo bar\n", get_logfile(1));