]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: make clang analyzer happy
authorRuediger Meier <ruediger.meier@ga-group.nl>
Tue, 27 Jun 2017 18:33:28 +0000 (20:33 +0200)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Thu, 29 Jun 2017 12:04:21 +0000 (14:04 +0200)
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@ga-group.nl>
sys-utils/lscpu.c

index 83f3a7d2791e28e4f0b2360ca5cb3fce29684fa5..852711e74b36020642c6e25e72c757c4c667aead 100644 (file)
@@ -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++)