uniq: don't continue field processing after end of line
authorSami Kerola <kerolasa@iki.fi>
Sun, 16 Jan 2011 23:27:06 +0000 (00:27 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 17 Jan 2011 18:07:58 +0000 (19:07 +0100)
* NEWS (Bug fixes): Mention it.
* src/uniq.c (find_field): Stop processing loop when end of line
is reached.  Before this fix, 'uniq -f 10000000000 /etc/passwd'
would run for a very long time.

NEWS
src/uniq.c

diff --git a/NEWS b/NEWS
index 9ccad63..3ec35c7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ GNU coreutils NEWS                                    -*- outline -*-
   rm -f no longer fails for EINVAL or EILSEQ on file systems that
   reject file names invalid for that file system.
 
+  uniq -f NUM no longer tries to process fields after end of line.
+
 
 * Noteworthy changes in release 8.9 (2011-01-04) [stable]
 
index 7bdbc4f..9c7e37c 100644 (file)
@@ -214,7 +214,7 @@ find_field (struct linebuffer const *line)
   size_t size = line->length - 1;
   size_t i = 0;
 
-  for (count = 0; count < skip_fields; count++)
+  for (count = 0; count < skip_fields && i < size; count++)
     {
       while (i < size && isblank (to_uchar (lp[i])))
         i++;