From: Jim Meyering Date: Tue, 18 May 2010 09:58:32 +0000 (+0200) Subject: linuxNodeInfoCPUPopulate: avoid used-uninitialized via a test X-Git-Tag: v0.8.2~255 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43beb82ecaef397c820933480f6cc5af155a4d4d;p=thirdparty%2Flibvirt.git linuxNodeInfoCPUPopulate: avoid used-uninitialized via a test * 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. --- diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c index 9aeb459924..ff056b93b5 100644 --- a/tests/nodeinfotest.c +++ b/tests/nodeinfotest.c @@ -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;