summaryrefslogtreecommitdiff
path: root/src/join.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2006-12-13 22:03:54 +0100
committerJim Meyering <jim@meyering.net>2006-12-13 22:03:54 +0100
commitec95137cc376119f634610a7683a296fc7b78ea4 (patch)
tree52d315f085e18022db44722d7e58f3e4635d84d9 /src/join.c
parentae3ee95eb8372ec5947e3c790c6ea77bc703c160 (diff)
downloadcoreutils-ec95137cc376119f634610a7683a296fc7b78ea4.tar.xz
Remove some arbitrary restrictions on size fields,
so that commands like "sort -k 18446744073709551616" no longer fail merely because 18446744073709551616 doesn't fit in uintmax_t. The trick is that these fields can all be treated as effectively infinity; their exact values don't matter, since no internal buffer can be that long. * src/join.c (string_to_join_field): Verify that SIZE_MAX <= ULONG_MAX if the code assumes this. Silently truncate too-large values to SIZE_MAX, as the remaining code will do the right thing in this case. * src/sort.c (parse_field_count): Likewise. * src/uniq.c (size_opt, main): Likewise. * tests/join/Test.pm (bigfield): New test. * tests/sort/Test.pm (bigfield): New test. * tests/uniq/Test.pm (121): New test. Signed-off-by: Jim Meyering <jim@meyering.net>
Diffstat (limited to 'src/join.c')
-rw-r--r--src/join.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/join.c b/src/join.c
index 77a389604..b113c543b 100644
--- a/src/join.c
+++ b/src/join.c
@@ -599,7 +599,8 @@ add_field (int file, size_t field)
/* Convert a string of decimal digits, STR (the 1-based join field number),
to an integral value. Upon successful conversion, return one less
- (the zero-based field number). If it cannot be converted, give a
+ (the zero-based field number). Silently convert too-large values
+ to SIZE_MAX - 1. Otherwise, if a value cannot be converted, give a
diagnostic and exit. */
static size_t
@@ -607,16 +608,12 @@ string_to_join_field (char const *str)
{
size_t result;
unsigned long int val;
+ verify (SIZE_MAX <= ULONG_MAX);
strtol_error s_err = xstrtoul (str, NULL, 10, &val, "");
if (s_err == LONGINT_OVERFLOW || (s_err == LONGINT_OK && SIZE_MAX < val))
- {
- error (EXIT_FAILURE, 0,
- _("value %s is so large that it is not representable"),
- quote (str));
- }
-
- if (s_err != LONGINT_OK || val == 0)
+ val = SIZE_MAX;
+ else if (s_err != LONGINT_OK || val == 0)
error (EXIT_FAILURE, 0, _("invalid field number: %s"), quote (str));
result = val - 1;