]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: fix bug with EOF at buffer refill
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 27 Jul 2010 03:51:02 +0000 (20:51 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 27 Jul 2010 03:51:19 +0000 (20:51 -0700)
* src/sort.c (fillbuf): Don't append eol unless the line is nonempty.
This fixes a bug that was partly but not completely fixed by
the aadc67dfdb47f28bb8d1fa5e0fe0f52e2a8c51bf commit (dated July 15).
* tests/misc/sort (realloc-buf-2): New test, which catches this
bug on 64-bit hosts.

src/sort.c
tests/misc/sort

index 2ee5a1d4fc1e21fb0898a9295cce1b1e1443a3f9..588bae80f614e5892e57df4160e1cdf825c90bae 100644 (file)
@@ -1727,7 +1727,7 @@ fillbuf (struct buffer *buf, FILE *fp, char const *file)
                   buf->eof = true;
                   if (buf->buf == ptrlim)
                     return false;
-                  if (ptrlim[-1] != eol)
+                  if (line_start != ptrlim && ptrlim[-1] != eol)
                     *ptrlim++ = eol;
                 }
             }
index 0b098452d0ecad895b170d5cb755ad97f070145e..de189ddb9fa2a5cefa01e78982c85fc4df4a476b 100755 (executable)
@@ -367,6 +367,7 @@ my @Tests =
 # Exercise the code that enlarges the line buffer.  See the thread here:
 # http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/11006
 ['realloc-buf', '-S1', {IN=>'a'x4000 ."\n"}, {OUT=>'a'x4000 ."\n"}],
+['realloc-buf-2', '-S1', {IN=>'a'x5 ."\n"}, {OUT=>'a'x5 ."\n"}],
 
 ["sort-numeric", '--sort=numeric', {IN=>".01\n0\n"}, {OUT=>"0\n.01\n"}],
 ["sort-gennum", '--sort=general-numeric',