X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=miscutils%2Ftaskset.c;h=b43d42e905374cef5a374cce97236b47946cf285;hb=27842288b393e532e5693f2a2bab94fee73a326d;hp=bf98ea15d1bf5056fcc9e26bd88d8a781cfa5cc8;hpb=45ecfc2f5cda05dc9a2091ac610af03a8314ca4a;p=oweals%2Fbusybox.git diff --git a/miscutils/taskset.c b/miscutils/taskset.c index bf98ea15d..b43d42e90 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c @@ -7,41 +7,62 @@ */ #include -#include /* optind */ #include "libbb.h" #if ENABLE_FEATURE_TASKSET_FANCY #define TASKSET_PRINTF_MASK "%s" -#define from_cpuset(x) __from_cpuset(&x) /* craft a string from the mask */ -static char *__from_cpuset(cpu_set_t *mask) +static char *from_cpuset(cpu_set_t *mask) { int i; - char *ret = 0, *str = xzalloc(9); + char *ret = NULL; + char *str = xzalloc((CPU_SETSIZE / 4) + 1); /* we will leak it */ for (i = CPU_SETSIZE - 4; i >= 0; i -= 4) { - char val = 0; + int val = 0; int off; for (off = 0; off <= 3; ++off) - if (CPU_ISSET(i+off, mask)) - val |= 1<", * or it was "-p " and we came here @@ -94,8 +115,10 @@ int taskset_main(int argc ATTRIBUTE_UNUSED, char **argv) unsigned i; /* Do not allow zero mask: */ unsigned long long m = xstrtoull_range(aff, 0, 1, ULLONG_MAX); + enum { CNT_BIT = CPU_SETSIZE < sizeof(m)*8 ? CPU_SETSIZE : sizeof(m)*8 }; + CPU_ZERO(&mask); - for (i = 0; i < CPU_SETSIZE; i++) { + for (i = 0; i < CNT_BIT; i++) { unsigned long long bit = (1ULL << i); if (bit & m) CPU_SET(i, &mask);