coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[coreutils] [PATCH] sort: fix bug with EOF at buffer refill


From: Paul Eggert
Subject: [coreutils] [PATCH] sort: fix bug with EOF at buffer refill
Date: Mon, 26 Jul 2010 20:53:32 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100527 Thunderbird/3.0.5

* 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      |    2 +-
 tests/misc/sort |    1 +
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/sort.c b/src/sort.c
index 2ee5a1d..588bae8 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 0b09845..de189dd 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',
-- 
1.7.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]