diff options
author | Pádraig Brady <P@draigBrady.com> | 2014-12-16 12:36:39 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2014-12-19 11:56:20 +0000 |
commit | 6894816c653adef54f3a85becbf75a865d6d39d6 (patch) | |
tree | 82bb3126d3c8cfaeebc950bd03a52a4f5e0f056c /src/shred.c | |
parent | 178f8e79dcd1e0b8bbb3b04da664d05eaae56186 (diff) | |
download | coreutils-6894816c653adef54f3a85becbf75a865d6d39d6.tar.xz |
diagnose too-large numbers better
Following on from commit v8.23-82-gaddae94, consistently diagnose
numbers that are too large, so as to distinguish from other errors,
and make the limits obvious.
* gl/modules/xdectoint: A new module implementing xdecto[iu]max(),
which handles the common case of parsing a bounded integer and
exiting with a diagnostic on error.
* gl/lib/xdectoimax.c: The signed variant.
* gl/lib/xdectoint.c: The parameterized implementation.
* gl/lib/xdectoint.h: The interface.
* gl/lib/xdectoumax.c: The unsigned variant.
* bootstrap.conf: Reference the new module.
* cfg.mk (exclude_file_name_regexp--sc_require_config_h_first):
Exclude the parameterized templates.
* src/csplit.c: Output EOVERFLOW or ERANGE errors if appropriate.
* src/fmt.c: Likewise.
* src/fold.c: Likewise.
* src/head.c: Likewise.
* src/ls.c: Likewise.
* src/nl.c: Likewise.
* src/nproc.c: Likewise.
* src/shred.c: Likewise.
* src/shuf.c: Likewise.
* src/stdbuf.c: Likewise.
* src/stty.c: Likewise.
* src/tail.c: Likewise.
* src/truncate.c: Likewise.
* src/split.c: Likewise.
* src/pr.c: Likewise.
* tests/pr/pr-tests.pl: Adjust to avoid matching errno diagnostic.
* tests/fmt/base.pl: Likewise.
* tests/split/l-chunk.sh: Likewise.
* tests/misc/shred-negative.sh: Likewise.
* tests/misc/tail.pl: Likewise. Also remove the redundant
existing ERR_SUBST from test err-6.
* tests/ls/hex-option.sh: Check HEX/OCT options.
* tests/misc/shred-size.sh: Likewise.
* tests/misc/stty-row-col.sh: Likewise.
Diffstat (limited to 'src/shred.c')
-rw-r--r-- | src/shred.c | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/shred.c b/src/shred.c index b235b29ae..2e5719914 100644 --- a/src/shred.c +++ b/src/shred.c @@ -86,7 +86,7 @@ #include "system.h" #include "argmatch.h" -#include "xstrtol.h" +#include "xdectoint.h" #include "error.h" #include "fcntl--.h" #include "human.h" @@ -1228,16 +1228,10 @@ main (int argc, char **argv) break; case 'n': - { - uintmax_t tmp; - if (xstrtoumax (optarg, NULL, 10, &tmp, NULL) != LONGINT_OK - || MIN (ULONG_MAX, SIZE_MAX / sizeof (int)) <= tmp) - { - error (EXIT_FAILURE, 0, _("%s: invalid number of passes"), - quotearg_colon (optarg)); - } - flags.n_iterations = tmp; - } + flags.n_iterations = xdectoumax (optarg, 0, + MIN (ULONG_MAX, + SIZE_MAX / sizeof (int)), "", + _("invalid number of passes"), 0); break; case RANDOM_SOURCE_OPTION: @@ -1255,17 +1249,8 @@ main (int argc, char **argv) break; case 's': - { - uintmax_t tmp; - if ((xstrtoumax (optarg, NULL, 0, &tmp, "cbBkKMGTPEZY0") - != LONGINT_OK) - || OFF_T_MAX < tmp) - { - error (EXIT_FAILURE, 0, _("%s: invalid file size"), - quotearg_colon (optarg)); - } - flags.size = tmp; - } + flags.size = xnumtoumax (optarg, 0, 0, OFF_T_MAX, "cbBkKMGTPEZY0", + _("invalid file size"), 0); break; case 'v': |