summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2012-11-24 11:36:15 -0800
committerJim Meyering <jim@meyering.net>2012-11-24 15:23:31 -0800
commit06aeeecb3fe2655fd5e4e12948b389873a79884b (patch)
treef779e7817903f75566e21451dcbb279fc9161f2f /src
parent1b874511b60252a5c71c7a29046afdc99e5391bb (diff)
downloadcoreutils-06aeeecb3fe2655fd5e4e12948b389873a79884b.tar.xz
cut: do not print extraneous delimiters in some unusual cases
When printing output delimiters, and when a to-EOL range subsumes at least one other range, cut would mistakenly print delimiters for the subsumed range. This bug was probably introduced via commit v5.2.1-639-g847e066. * src/cut.c (set_fields): Ignore any range that is subsumed by a to-EOL range. Also, move two declarations down. * tests/misc/cut.pl: Add tests to exercise this. * NEWS (Bug fixes): Mention it. Reported by Marcel Böhme in http://bugs.gnu.org/12966
Diffstat (limited to 'src')
-rw-r--r--src/cut.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/cut.c b/src/cut.c
index b464840d7..4219d24e9 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -514,17 +514,18 @@ set_fields (const char *fieldstr)
/* Set the array entries corresponding to integers in the ranges of RP. */
for (i = 0; i < n_rp; i++)
{
- size_t j;
- size_t rsi_candidate;
+ /* Ignore any range that is subsumed by the to-EOL range. */
+ if (eol_range_start && eol_range_start <= rp[i].lo)
+ continue;
/* Record the range-start indices, i.e., record each start
index that is not part of any other (lo..hi] range. */
- rsi_candidate = complement ? rp[i].hi + 1 : rp[i].lo;
+ size_t rsi_candidate = complement ? rp[i].hi + 1 : rp[i].lo;
if (output_delimiter_specified
&& !is_printable_field (rsi_candidate))
mark_range_start (rsi_candidate);
- for (j = rp[i].lo; j <= rp[i].hi; j++)
+ for (size_t j = rp[i].lo; j <= rp[i].hi; j++)
mark_printable_field (j);
}