]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/cpuset: exit early from cpulist_parse
authorThomas Weißschuh <thomas@t-8ch.de>
Thu, 1 Feb 2024 19:09:41 +0000 (20:09 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Thu, 1 Feb 2024 19:09:41 +0000 (20:09 +0100)
If `a` exceeds `max`, any increment of `a` will also `exceed` max.
In this case the CPU_SET_S will never do anything all additional loops
are wasted.

Fixes #2748

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
lib/cpuset.c

index 643537f6d9f1bc40f2800e1e017aa0ec88ab65c4..533b8ab309b1d222558cbfc4b88e9c96aee48e42 100644 (file)
@@ -326,8 +326,12 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail)
                if (!(a <= b))
                        return 1;
                while (a <= b) {
-                       if (fail && (a >= max))
-                               return 2;
+                       if (a >= max) {
+                               if (fail)
+                                       return 2;
+                               else
+                                       break;
+                       }
                        CPU_SET_S(a, setsize, set);
                        a += s;
                }