summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorey Hickey <bugfood-c@fatooh.org>2022-01-23 17:23:39 -0800
committerTheodore Ts'o <tytso@mit.edu>2023-02-01 11:37:01 -0500
commit5c04fdf8ce4dfc35cd36084d7feeca1a11dfedab (patch)
treeed3add71f2efbb11715938b601ed7ddee4b8c638
parentc4efea445e952c06a410cc3b0b89763cc4650fb7 (diff)
downloade2fsprogs-5c04fdf8ce4dfc35cd36084d7feeca1a11dfedab.tar.gz
badblocks: print a more explanatory message when a parameter is too large
Before: $ misc/badblocks -w -b 4294967296 -c 1 /tmp/testfile.bin misc/badblocks: invalid block size - 4294967296 After: $ misc/badblocks -w -b 4294967296 -c 1 /tmp/testfile.bin misc/badblocks: block size too large - 4294967296 The original error is retained for invalid arguments, e.g.: $ misc/badblocks -w -b foo -c 1 /tmp/testfile.bin misc/badblocks: invalid block size - foo Signed-off-by: Corey Hickey <bugfood-c@fatooh.org> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--misc/badblocks.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/misc/badblocks.c b/misc/badblocks.c
index 3dedf763..85a53b01 100644
--- a/misc/badblocks.c
+++ b/misc/badblocks.c
@@ -1036,10 +1036,13 @@ static unsigned int parse_uint(const char *str, const char *descr)
errno = 0;
ret = strtoul(str, &tmp, 0);
- if (*tmp || errno || (ret > UINT_MAX) ||
- (ret == ULONG_MAX && errno == ERANGE)) {
+ if (*tmp || errno) {
com_err (program_name, 0, _("invalid %s - %s"), descr, str);
exit (1);
+ } else if ((ret > UINT_MAX) ||
+ (ret == ULONG_MAX && errno == ERANGE)) {
+ com_err (program_name, 0, _("%s too large - %lu"), descr, ret);
+ exit (1);
}
return ret;
}