GNU bug report logs - #12966
cut: Problems with overlapping, open-ended ranges

Previous Next

Package: coreutils;

Reported by: "Marcel Böhme" <hawkie <at> web.de>

Date: Fri, 23 Nov 2012 08:14:01 UTC

Severity: normal

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Jim Meyering <jim <at> meyering.net>
To: Marcel Böhme <hawkie <at> web.de>
Cc: 12966 <at> debbugs.gnu.org
Subject: bug#12966: cut: Problems with overlapping, open-ended ranges
Date: Sat, 24 Nov 2012 08:11:34 +0100
Marcel Böhme wrote:
>    I found two (semantically related) bugs. One seems to originate in the
>    first version. For research purposes, I would appreciate if you could
>    confirm that the second was introduced with Coreutils 5.3.0.
>    1) The following bug seems to exists "since the beginning".
>    $echo 1234567890 | ./cut -b 2-,3,4-4,5,9-
>    3590
>    $echo 1234567890 | ./cut -b 2-,3,4-4,5,9-10
>    234567890
>    $echo 1234567890 | ./cut -b 2-10,3,4-4,5,9-
>    234567890

Thank you for the reports!  That is definitely a bug.
Here's a proposed fix:
[I'll look at the other one tomorrow if no one
gets to it first. ]

From 99084373fb7a12888234958ff0961643cf029dae Mon Sep 17 00:00:00 2001
From: Jim Meyering <jim <at> meyering.net>
Date: Fri, 23 Nov 2012 23:09:10 -0800
Subject: [PATCH] cut: interpret "-b3-,2-" like "-b2-", not like "-b3-"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/cut.c (set_fields): When two right-open-ended ranges are
specified, don't blindly let the latter one take precedence over
the former.  Instead, use the union of the ranges.
* tests/misc/cut.pl: Add test to exercise this.
* THANKS.in: Attribute.
* NEWS (Bug fixes): Mention it.
Reported by Marcel Böhme in http://bugs.gnu.org/12966
---
 NEWS              | 4 ++++
 THANKS.in         | 1 +
 src/cut.c         | 6 ++++--
 tests/misc/cut.pl | 3 +++
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 15fddd4..284525e 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   Instead, cut now fails and emits an appropriate diagnostic.
   [This bug was present in "the beginning".]

+  cut now handles overlapping right-open-ended ranges properly.  Before,
+  it would interpret "-b3-,2-" like "-b3-".  Now it's treated like "-b2-".
+  [This bug was present in "the beginning".]
+
   install -m M SOURCE DEST no longer has a race condition where DEST's
   permissions are temporarily derived from SOURCE instead of from M.

diff --git a/THANKS.in b/THANKS.in
index 016a41e..3080cd3 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -367,6 +367,7 @@ Marc Haber                          mh+debian-bugs <at> zugschlus.de
 Marc Mengel                         mengel <at> fnal.gov
 Marc Lehman                         schmorp <at> schmorp.de
 Marc Olzheim                        marcolz <at> stack.nl
+Marcel Böhme                        hawkie <at> web.de
 Marco Franzen                       Marco.Franzen <at> Thyron.com
 Marcus Brinkmann                    http://www.marcus-brinkmann.de
 Marcus Daniels                      marcus <at> ee.pdx.edu
diff --git a/src/cut.c b/src/cut.c
index 2a57148..b464840 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -391,8 +391,10 @@ set_fields (const char *fieldstr)
                  In any case, 'initial' contains the start of the range. */
               if (!rhs_specified)
                 {
-                  /* 'n-'.  From 'initial' to end of line. */
-                  eol_range_start = initial;
+                  /* 'n-'.  From 'initial' to end of line.  If we've already
+                     seen an M- range, ignore subsequent N- unless N < M.  */
+                  if (eol_range_start == 0 || initial < eol_range_start)
+                    eol_range_start = initial;
                   field_found = true;
                 }
               else
diff --git a/tests/misc/cut.pl b/tests/misc/cut.pl
index cd56555..cb4781a 100755
--- a/tests/misc/cut.pl
+++ b/tests/misc/cut.pl
@@ -163,6 +163,9 @@ my @Tests =
   ['big-unbounded-b', '--output-d=:', '-b1234567890-', {IN=>''}, {OUT=>''}],
   ['big-unbounded-c', '--output-d=:', '-c1234567890-', {IN=>''}, {OUT=>''}],
   ['big-unbounded-f', '--output-d=:', '-f1234567890-', {IN=>''}, {OUT=>''}],
+
+  ['overlapping-unbounded-1', '-b3-,2-', {IN=>"1234\n"}, {OUT=>"234\n"}],
+  ['overlapping-unbounded-2', '-b2-,3-', {IN=>"1234\n"}, {OUT=>"234\n"}],
  );

 if ($mb_locale ne 'C')
--
1.8.0.251.g3a189da




This bug report was last modified 12 years and 175 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.