]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
bits: improve error message for out-of-range cpulist_parse()
authorWanBingjiang <wanbingjiang@webray.com.cn>
Wed, 29 Apr 2026 11:00:25 +0000 (19:00 +0800)
committerWanBingjiang <wanbingjiang@webray.com.cn>
Thu, 7 May 2026 01:51:19 +0000 (09:51 +0800)
Distinguish between invalid list syntax and CPU numbers that exceed
the cpuset size, giving the user a clearer diagnostic.

Signed-off-by: WanBingjiang <wanbingjiang@webray.com.cn>
tests/expected/bits/bits-truncate
tests/expected/bits/bits-truncate.err
tests/expected/bits/bits-truncate.exit_code
text-utils/bits.c

index d00491fd7e5bb6fa28c517a0bb32b8b506539d4d..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1 +0,0 @@
-1
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..5274a7d147a5f7aa77838f9b879a92cb9434bcbb 100644 (file)
@@ -0,0 +1 @@
+bits: error: bit list wider than cpuset size: 1,10000
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..56a6051ca2b02b04ef92d5150c9ef600403cb1de 100644 (file)
@@ -0,0 +1 @@
+1
\ No newline at end of file
index 7f2bac5f1aee4f4c22166fa72093aa41319f9cf8..532de50613630f8c921c90611a17a97ee604b413 100644 (file)
@@ -63,8 +63,11 @@ static void parse_mask_or_list(const char *cmdline_arg,
                if (cpumask_parse(arg, bits, size) < 0)
                        errx(EXIT_FAILURE, _("error: invalid bit mask: %s"), cmdline_arg);
        } else {
-               if (cpulist_parse(arg, bits, size, 1))
+               int rc = cpulist_parse(arg, bits, size, 1);
+               if (rc == 1)
                        errx(EXIT_FAILURE, _("error: invalid bit list: %s"), cmdline_arg);
+               else if (rc == 2)
+                       errx(EXIT_FAILURE, _("error: bit list wider than cpuset size: %s"), cmdline_arg);
        }
 
        /* truncate all bits beyond the requested mask size */