]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
badblocks: print a more explanatory message when a parameter is too large
authorCorey Hickey <bugfood-c@fatooh.org>
Mon, 24 Jan 2022 01:23:39 +0000 (17:23 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 1 Feb 2023 16:37:01 +0000 (11:37 -0500)
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>
misc/badblocks.c

index 3dedf763047d6fb86c74fa168f8da2f0b4649cf7..85a53b01f96307e4029e76722d4d5959940c6aeb 100644 (file)
@@ -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;
 }