mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-19 03:33:43 +03:00
cut: diagnose a range starting with 0 (-f 0-2) as invalid, and
give a better diagnostic for a field-number/offset of 0. * NEWS: Mention the fix. * src/cut.c (ADD_RANGE_PAIR): Add an explicit check for 0. Based on a patch from James Youngman. * tests/misc/cut: Add tests for the above.
This commit is contained in:
1 parent
ae5717158f
commit
a6a447fc58
4 files changed
+32
-6
No files matched your search
@@ -1,5 +1,12 @@
|
||||
2007-05-22 Jim Meyering <jim@meyering.net>
|
||||
|
||||
cut: diagnose a range starting with 0 (-f 0-2) as invalid, and
|
||||
give a better diagnostic for a field-number/offset of 0.
|
||||
* NEWS: Mention the fix.
|
||||
* src/cut.c (ADD_RANGE_PAIR): Add an explicit check.
|
||||
Based on a patch from James Youngman.
|
||||
* tests/misc/cut: Add tests for the above.
|
||||
|
||||
"cut -f 2-0" now fails; before, it was equivalent to "cut -f 2-"
|
||||
Also, diagnose the '-' in "cut -f -" as an invalid range, rather
|
||||
than interpreting it as the unlimited range, "1-".
|
||||
@@ -8,6 +15,7 @@
|
||||
of 0 as an unspecified range endpoint.
|
||||
Give better diagnostics.
|
||||
Adjust a comment so that it is true also for 64-bit size_t.
|
||||
|
||||
* tests/cut/Test.pm: Add tests for the above.
|
||||
|
||||
stty: fix a harmless syntax nit
|
||||
|
||||
@@ -12,6 +12,9 @@ GNU coreutils NEWS -*- outline -*-
|
||||
|
||||
** Bug fixes
|
||||
|
||||
cut now diagnoses a range starting with zero (e.g., -f 0-2) as invalid;
|
||||
before, it would treat it as if it started with 1 (-f 1-2).
|
||||
|
||||
"cut -f 2-0" now fails; before, it was equivalent to "cut -f 2-"
|
||||
|
||||
cut now diagnoses the '-' in "cut -f -" as an invalid range, rather
|
||||
|
||||
@@ -57,6 +57,8 @@
|
||||
#define ADD_RANGE_PAIR(rp, low, high) \
|
||||
do \
|
||||
{ \
|
||||
if (low == 0 || high == 0) \
|
||||
FATAL_ERROR (_("fields and positions are numbered from 1")); \
|
||||
if (n_rp >= n_rp_allocated) \
|
||||
{ \
|
||||
(rp) = X2NREALLOC (rp, &n_rp_allocated); \
|
||||
|
||||
+19
-6
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Test "cut". -*- perl -*-
|
||||
|
||||
# Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2006, 2007 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -27,7 +27,7 @@ $PERL -e 1 > /dev/null 2>&1 || {
|
||||
exit 77
|
||||
}
|
||||
|
||||
exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
|
||||
exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\FILE_EOF
|
||||
require 5.003;
|
||||
use strict;
|
||||
|
||||
@@ -36,16 +36,29 @@ use strict;
|
||||
# Turn off localisation of executable's ouput.
|
||||
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
|
||||
|
||||
my $prog = 'cut';
|
||||
my $diag = <<EOF;
|
||||
$prog: fields and positions are numbered from 1
|
||||
Try \`cut --help' for more information.
|
||||
EOF
|
||||
|
||||
my @Tests =
|
||||
(
|
||||
# Provoke a double-free in cut from coreutils-6.7.
|
||||
['dbl-free', '-f2-', {IN=>{f=>'x'}}, {IN=>{g=>'y'}}, {OUT=>"x\ny\n"}],
|
||||
# Provoke a double-free in cut from coreutils-6.7.
|
||||
['dbl-free', '-f2-', {IN=>{f=>'x'}}, {IN=>{g=>'y'}}, {OUT=>"x\ny\n"}],
|
||||
|
||||
# This failed (as it should) even before coreutils-6.10,
|
||||
# but cut from 6.10 produces a more useful diagnostic.
|
||||
['zero-1', '-b0', {ERR=>$diag}, {EXIT => 1} ],
|
||||
|
||||
# Before coreutils-6.10, specifying a range of 0-2 was not an error.
|
||||
# It was treated just like "-2".
|
||||
['zero-2', '-f0-2', {ERR=>$diag}, {EXIT => 1} ],
|
||||
);
|
||||
|
||||
my $save_temps = $ENV{DEBUG};
|
||||
my $verbose = $ENV{VERBOSE};
|
||||
|
||||
my $prog = 'cut';
|
||||
my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose);
|
||||
exit $fail;
|
||||
EOF
|
||||
FILE_EOF
|
||||
Reference in new issue
Block a user