]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: qemuxml2xml: Avoid crash when processing an XML that fails to parse
authorPeter Krempa <pkrempa@redhat.com>
Mon, 25 Jul 2016 08:33:03 +0000 (10:33 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 27 Jul 2016 07:39:26 +0000 (09:39 +0200)
Failure to parse a XML that was not supposed to fail would result into a
crash in the test suite as the vcpu bitmap would not be filled prior to
the active XML->XML test.

Skip formatting of the vcpu snippet in the fake status XML formatter in
such case to avoid the crash. The test would fail anyways.

tests/qemuxml2xmltest.c

index 8a184d271fea4b2cd1c60560bdcde884ab05df43..5f04b8b6f0d9858cbd8af6d63f2c87387c1a5709 100644 (file)
@@ -112,9 +112,12 @@ testGetStatuXMLPrefixVcpus(virBufferPtr buf,
     virBufferAddLit(buf, "<vcpus>\n");
     virBufferAdjustIndent(buf, 2);
 
-    while ((vcpuid = virBitmapNextSetBit(data->activeVcpus, vcpuid)) >= 0)
-        virBufferAsprintf(buf, "<vcpu id='%zd' pid='%zd'/>\n",
-                          vcpuid, vcpuid + 3803519);
+    /* Make sure we can format the fake vcpu list. The test will fail regardles. */
+    if (data->activeVcpus) {
+        while ((vcpuid = virBitmapNextSetBit(data->activeVcpus, vcpuid)) >= 0)
+            virBufferAsprintf(buf, "<vcpu id='%zd' pid='%zd'/>\n",
+                              vcpuid, vcpuid + 3803519);
+    }
 
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</vcpus>\n");