cgfsng: lxc_cpumask_to_cpulist()

parent d5d468f6
...@@ -448,24 +448,31 @@ static uint32_t *lxc_cpumask(char *buf, size_t nbits) ...@@ -448,24 +448,31 @@ static uint32_t *lxc_cpumask(char *buf, size_t nbits)
/* Turn cpumask into simple, comma-separated cpulist. */ /* Turn cpumask into simple, comma-separated cpulist. */
static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits) static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
{ {
size_t i;
int ret; int ret;
char numstr[LXC_NUMSTRLEN64] = {0}; size_t i;
char **cpulist = NULL; char **cpulist = NULL;
char numstr[LXC_NUMSTRLEN64] = {0};
for (i = 0; i <= nbits; i++) { for (i = 0; i <= nbits; i++) {
if (is_set(i, bitarr)) { if (!is_set(i, bitarr))
ret = snprintf(numstr, LXC_NUMSTRLEN64, "%zu", i); continue;
if (ret < 0 || (size_t)ret >= LXC_NUMSTRLEN64) {
lxc_free_array((void **)cpulist, free); ret = snprintf(numstr, LXC_NUMSTRLEN64, "%zu", i);
return NULL; if (ret < 0 || (size_t)ret >= LXC_NUMSTRLEN64) {
} lxc_free_array((void **)cpulist, free);
if (lxc_append_string(&cpulist, numstr) < 0) { return NULL;
lxc_free_array((void **)cpulist, free); }
return NULL;
} ret = lxc_append_string(&cpulist, numstr);
if (ret < 0) {
lxc_free_array((void **)cpulist, free);
return NULL;
} }
} }
if (!cpulist)
return NULL;
return lxc_string_join(",", (const char **)cpulist, false); return lxc_string_join(",", (const char **)cpulist, false);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment