From: Ruediger Meier <ruediger.meier@xxxxxxxxxxx> Let read_nodes() work on uninitialized structs to silence these two warnings: CC sys-utils/lscpu-lscpu.o warning: Path diagnostic report is not generated. Current output format does not support diagnostics that cross file boundaries. Refer to --analyzer-output for valid output formats In file included from sys-utils/lscpu.c:63: ./include/xalloc.h:32:21: warning: Call to 'malloc' has an allocation size of 0 bytes void *ret = malloc(size); ^~~~~~~~~~~~ sys-utils/lscpu.c:1468:23: warning: Function call argument is an uninitialized value desc->nodemaps[i] = path_read_cpuset(maxcpus, ^~~~~~~~~~~~~~~~~~~~~~~~~ 2 warnings generated. Signed-off-by: Ruediger Meier <ruediger.meier@xxxxxxxxxxx> --- sys-utils/lscpu.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 83f3a7d..852711e 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -1432,35 +1432,34 @@ read_nodes(struct lscpu_desc *desc) struct dirent *d; const char *path; + desc->nnodes = 0; + /* number of NUMA node */ if (!(path = path_get(_PATH_SYS_NODE))) return; - dir = opendir(path); - - while (dir && (d = readdir(dir))) { + if (!(dir = opendir(path))) + return; + while ((d = readdir(dir))) { if (is_node_dirent(d)) desc->nnodes++; } if (!desc->nnodes) { - if (dir) - closedir(dir); + closedir(dir); return; } desc->nodemaps = xcalloc(desc->nnodes, sizeof(cpu_set_t *)); desc->idx2nodenum = xmalloc(desc->nnodes * sizeof(int)); - if (dir) { - rewinddir(dir); - while ((d = readdir(dir)) && i < desc->nnodes) { - if (is_node_dirent(d)) - desc->idx2nodenum[i++] = strtol_or_err(((d->d_name) + 4), - _("Failed to extract the node number")); - } - closedir(dir); - qsort(desc->idx2nodenum, desc->nnodes, sizeof(int), nodecmp); + rewinddir(dir); + while ((d = readdir(dir)) && i < desc->nnodes) { + if (is_node_dirent(d)) + desc->idx2nodenum[i++] = strtol_or_err(((d->d_name) + 4), + _("Failed to extract the node number")); } + closedir(dir); + qsort(desc->idx2nodenum, desc->nnodes, sizeof(int), nodecmp); /* information about how nodes share different CPUs */ for (i = 0; i < desc->nnodes; i++) -- 1.8.5.6 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html