[libvirt] [PATCH] nodeinfo: avoid uninitialized variable on error

Commit 8ba0a58 introduced a compiler warning that I hit during a run of ./autobuild.sh: ../../src/nodeinfo.c: In function 'nodeCapsInitNUMA': ../../src/nodeinfo.c:1853:43: error: 'nsiblings' may be used uninitialized in this function [-Werror=maybe-uninitialized] if (virCapabilitiesAddHostNUMACell(caps, n, memory, ^ Sure enough, nsiblings starts uninitialized, and is set by a call to virNodeCapsGetSiblingInfo, but that function fails to assign through the pointer if virNumaGetDistances fails. * src/nodeinfo.c (nodeCapsInitNUMA): Initialize nsiblings. Signed-off-by: Eric Blake <eblake@redhat.com> --- Pushing under the build-breaker rule. src/nodeinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 5eef42e..5332ede 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -1803,7 +1803,7 @@ nodeCapsInitNUMA(virCapsPtr caps) virCapsHostNUMACellCPUPtr cpus = NULL; virBitmapPtr cpumap = NULL; virCapsHostNUMACellSiblingInfoPtr siblings = NULL; - int nsiblings; + int nsiblings = 0; int ret = -1; int ncpus = 0; int cpu; -- 1.9.3

On 11.06.2014 00:27, Eric Blake wrote:
Commit 8ba0a58 introduced a compiler warning that I hit during a run of ./autobuild.sh:
../../src/nodeinfo.c: In function 'nodeCapsInitNUMA': ../../src/nodeinfo.c:1853:43: error: 'nsiblings' may be used uninitialized in this function [-Werror=maybe-uninitialized] if (virCapabilitiesAddHostNUMACell(caps, n, memory, ^
Sure enough, nsiblings starts uninitialized, and is set by a call to virNodeCapsGetSiblingInfo, but that function fails to assign through the pointer if virNumaGetDistances fails.
If that's the case, virNodeCapsGetSiblingInfo() fails too so at the incriminated lines we jump at cleanup label directly. But maybe the compiler you've used fails to do analysis this deep. Michal
participants (2)
-
Eric Blake
-
Michal Privoznik