diff --git a/src/sort.c b/src/sort.c index 2ee5a1d4f..588bae80f 100644 --- a/src/sort.c +++ b/src/sort.c @@ -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; } } diff --git a/tests/misc/sort b/tests/misc/sort index 0b098452d..de189ddb9 100755 --- a/tests/misc/sort +++ b/tests/misc/sort @@ -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',