]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: Ignore fields where end position is before the start position
authorCliff Miller <cbm@whatexit.org>
Thu, 11 Jun 2009 17:30:32 +0000 (18:30 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 13 Jun 2009 00:25:06 +0000 (01:25 +0100)
* NEWS: Mention the fix
* THANKS: Add Cliff Miller
* src/sort.c (keycompare): Ensure lima >= texta
* tests/misc/sort: Add 3 corresponding tests

Signed-off-by: Pádraig Brady <P@draigBrady.com>
NEWS
THANKS
src/sort.c
tests/misc/sort

diff --git a/NEWS b/NEWS
index 0455d592d1f668821f2963b5c8f2ebf62ed052ad..d7695e4a2d304e7920f01dddbbb298818fb647ef 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,11 @@ GNU coreutils NEWS                                    -*- outline -*-
   truncate -s failed to skip all whitespace in the option argument in
   some locales.
 
+  sort now correctly ignores fields whose ending position is specified
+  before the start position. Previously in numeric mode the remaining
+  part of the line after the start position was used as the sort key.
+  [This bug appears to have been present in "the beginning".]
+
 ** Changes in behavior
 
   ls --color: files with multiple hard links are no longer colored differently
diff --git a/THANKS b/THANKS
index 4392f04fdb48727e744ba39100613431b72a46ee..bcd88f087b59b80cf6363577dee846102d200fff 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -112,6 +112,7 @@ Christophe LYON                     christophe.lyon@st.com
 Chuck Hedrick                       hedrick@klinzhai.rutgers.edu
 Clark Morgan                        cmorgan@aracnet.com
 Clement Wang                        clem.wang@overture.com
+Cliff Miller                        cbm@whatexit.org
 Colin Plumb                         colin@nyx.net
 Colin Watson                        cjw44@riva.ucam.org
 Collin Rogowski                     collin@rogowski.de
index d571ddf0238e2374b3d7f326d9a387927a06cc76..6acec070da1bc3ab934e1544ff6b29cb16c29a50 100644 (file)
@@ -1998,9 +1998,13 @@ keycompare (const struct line *a, const struct line *b)
       char const *translate = key->translate;
       bool const *ignore = key->ignore;
 
+      /* Treat field ends before field starts as empty fields.  */
+      lima = MAX (texta, lima);
+      limb = MAX (textb, limb);
+
       /* Find the lengths. */
-      size_t lena = lima <= texta ? 0 : lima - texta;
-      size_t lenb = limb <= textb ? 0 : limb - textb;
+      size_t lena = lima - texta;
+      size_t lenb = limb - textb;
 
       /* Actually compare the fields. */
 
index ae3bd8e49c50d2a500fc71492124cf443bb6c926..21e7af8e92fab5b467ae011da7b504cbe50b783c 100755 (executable)
@@ -134,6 +134,10 @@ my @Tests =
 ["07d", '+1 -3', {IN=>"y k b\nz k a\n"}, {OUT=>"z k a\ny k b\n"}],
 # ensure a character position of 0 includes whole field
 ["07e", '-k 2,3.0', {IN=>"a a b\nz a a\n"}, {OUT=>"z a a\na a b\n"}],
+# ensure fields with end position before start are ignored
+["07f", '-n -k1.3,1.1', {IN=>"a 2\nb 1\n"}, {OUT=>"a 2\nb 1\n"}],
+["07g", '-n -k2.2,1.2', {IN=>"aa 2\nbb 1\n"}, {OUT=>"aa 2\nbb 1\n"}],
+["07h", '-k1.3nb,1.3', {IN=>"  a 2\n  b 1\n"}, {OUT=>"  a 2\n  b 1\n"}],
 #
 # report an error for `.' without following char spec
 ["08a", '-k 2.,3', {EXIT=>2},