From: Karel Zak Date: Tue, 3 Nov 2020 08:44:22 +0000 (+0100) Subject: lscpu: assume gaps in list of CPUs X-Git-Tag: v2.37-rc1~308 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6648a70eb2af821c768594be68c75ec01562af40;p=thirdparty%2Futil-linux.git lscpu: assume gaps in list of CPUs Signed-off-by: Karel Zak --- diff --git a/sys-utils/lscpu-cpu.c b/sys-utils/lscpu-cpu.c index f2159bd038..70b40c5413 100644 --- a/sys-utils/lscpu-cpu.c +++ b/sys-utils/lscpu-cpu.c @@ -45,16 +45,16 @@ void lscpu_unref_cpu(struct lscpu_cpu *cpu) */ int lscpu_create_cpus(struct lscpu_cxt *cxt, cpu_set_t *cpuset, size_t setsize) { - size_t n; + size_t n, i; assert(!cxt->cpus); cxt->npossibles = CPU_COUNT_S(setsize, cpuset); cxt->cpus = xcalloc(1, cxt->npossibles * sizeof(struct lscpu_cpu *)); - for (n = 0; n < cxt->npossibles; n++) { + for (n = 0, i = 0; n < (size_t) cxt->maxcpus && i < cxt->npossibles; n++) { if (CPU_ISSET_S(n, setsize, cpuset)) - cxt->cpus[n] = lscpu_new_cpu(n); + cxt->cpus[i++] = lscpu_new_cpu(n); } return 0;