From: Ruediger Meier Date: Tue, 27 Jun 2017 18:33:28 +0000 (+0200) Subject: lscpu: make clang analyzer happy X-Git-Tag: v2.31-rc1~233^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a25fb9e8ec534589bcc9f2fb45b4dfdc4d1084f7;p=thirdparty%2Futil-linux.git lscpu: make clang analyzer happy 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 --- diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 83f3a7d279..852711e74b 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++)