2007-05-22 James Youngman <[EMAIL PROTECTED]>
* src/cut.c (sanity_check_pos): check arguments to -f and -c
to better diagnose possible use of column 0, which is
invalid. These were previously being rejected, correctly
so, but with a less than helpful error message.
(ADD_RANGE_PAIR): call sanity_check_pos
(set_fields): remove a special case for value==0, because
ADD_RANGE_PAIR rejects it anyway.
The patch itself is attached instead of pasted inline to avoid
space/tab problems.
James.
2007-05-22 James Youngman <[EMAIL PROTECTED]>
* src/cut.c (sanity_check_pos): check arguments to -f and -c
to better diagnose possible use of column 0, which is
invalid. These were previously being rejected, correctly
so, but with a less than helpful error message.
(ADD_RANGE_PAIR): call sanity_check_pos
(set_fields): remove a special case for value==0, because
ADD_RANGE_PAIR rejects it anyway.
Index: src/cut.c
===================================================================
RCS file: /sources/coreutils/coreutils/src/cut.c,v
retrieving revision 1.131
diff -u -p -r1.131 cut.c
--- src/cut.c 16 Apr 2007 14:26:44 -0000 1.131
+++ src/cut.c 22 May 2007 01:37:01 -0000
@@ -57,6 +57,8 @@
#define ADD_RANGE_PAIR(rp, low, high) \
do \
{ \
+ sanity_check_pos (low); \
+ sanity_check_pos (high); \
if (n_rp >= n_rp_allocated) \
{ \
(rp) = X2NREALLOC (rp, &n_rp_allocated); \
@@ -318,6 +320,19 @@ compare_ranges (const void *a, const voi
return a_start < b_start ? -1 : a_start > b_start;
}
+/* Exit fatally if the indicated field/position number is invalid.
+ */
+static void
+sanity_check_pos (size_t val)
+{
+ if (!val)
+ {
+ FATAL_ERROR (_("fields and positions are numbered from 1"));
+ }
+}
+
+
+
/* Given the list of field or byte range specifications FIELDSTR, set
MAX_RANGE_ENDPOINT and allocate and initialize the PRINTABLE_FIELD
array. If there is a right-open-ended range, set EOL_RANGE_START
@@ -432,7 +447,7 @@ set_fields (const char *fieldstr)
value = 0;
}
}
- else if (value != 0)
+ else
{
/* A simple field number, not a range. */
ADD_RANGE_PAIR (rp, value, value);
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils