]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virDomainVcpuParse: Assign default vcpus count based on return value of virXMLPropUInt
authorPeter Krempa <pkrempa@redhat.com>
Thu, 6 May 2021 13:07:04 +0000 (15:07 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 7 May 2021 08:06:18 +0000 (10:06 +0200)
Assign the vcpu count when virXMLPropUInt returns '0' meaning that the
cpu count was not present in the XML. This will allow to always
initialize the value of @result in virXMLPropUInt to prevent use of
uninitialized values.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c

index f536630d720ae18eeac41710510783cc9beca996..a2dd7d649fd20479445db31b799f9c38bfdc9b3d 100644 (file)
@@ -18030,6 +18030,7 @@ virDomainVcpuParse(virDomainDef *def,
     unsigned int vcpus;
     g_autofree char *tmp = NULL;
     g_autofree xmlNodePtr *nodes = NULL;
+    int rc;
 
     vcpus = maxvcpus = 1;
 
@@ -18044,10 +18045,11 @@ virDomainVcpuParse(virDomainDef *def,
         }
         VIR_FREE(tmp);
 
-        vcpus = maxvcpus;
-
-        if (virXMLPropUInt(vcpuNode, "current", 10, VIR_XML_PROP_NONE, &vcpus) < 0)
+        if ((rc = virXMLPropUInt(vcpuNode, "current", 10, VIR_XML_PROP_NONE, &vcpus)) < 0) {
             return -1;
+        } else if (rc == 0) {
+            vcpus = maxvcpus;
+        }
 
         def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC;
         if (virXMLPropEnum(vcpuNode, "placement",