]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
linuxNodeInfoCPUPopulate: avoid used-uninitialized via a test
authorJim Meyering <meyering@redhat.com>
Tue, 18 May 2010 09:58:32 +0000 (11:58 +0200)
committerJim Meyering <meyering@redhat.com>
Tue, 18 May 2010 17:23:32 +0000 (19:23 +0200)
* tests/nodeinfotest.c (linuxTestCompareFiles): Don't use
nodeinfo->member uninitialized.  linuxNodeInfoCPUPopulate requires
that some of its nodeinfo members (including threads) be initialized
upon input.  The nodeinfotest.c program lacked the initialization,
while the only other use (nodeGetInfo) did perform it.
It's not trivial to move the initialization into the function,
since nodeGetInfo sets at least one member after clearing the
buffer but before calling linuxNodeInfoCPUPopulate.

tests/nodeinfotest.c

index 9aeb459924bf619e14d59e0d97aec0a372be45eb..ff056b93b575cb3bc65738e4dff2df239981ea52 100644 (file)
@@ -40,6 +40,8 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile
     cpuinfo = fopen(cpuinfofile, "r");
     if (!cpuinfo)
         return -1;
+
+    memset(&nodeinfo, 0, sizeof(nodeinfo));
     if (linuxNodeInfoCPUPopulate(cpuinfo, &nodeinfo) < 0) {
         fclose(cpuinfo);
         return -1;