Blob Blame History Raw
From a7e224cdad4aae6641fed84cdad621e7fecc8dc7 Mon Sep 17 00:00:00 2001
Message-Id: <a7e224cdad4aae6641fed84cdad621e7fecc8dc7@dist-git>
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Wed, 24 Aug 2016 16:10:53 -0400
Subject: [PATCH] Fix logic in qemuDomainObjPrivateXMLParseVcpu

https://bugzilla.redhat.com/show_bug.cgi?id=1097930
https://bugzilla.redhat.com/show_bug.cgi?id=1224341

The code in qemuDomainObjPrivateXMLParseVcpu for parsing
the 'idstr' string was comparing the overall boolean
result against 0 which was always true

qemu/qemu_domain.c: In function 'qemuDomainObjPrivateXMLParseVcpu':
qemu/qemu_domain.c:1482:59: error: comparison of constant '0' with boolean expression is always false [-Werror=bool-compare]
     if ((idstr && virStrToLong_uip(idstr, NULL, 10, &idx)) < 0 ||
                                                           ^

It was further performing two distinct error checks in
the same conditional and reporting a single error message,
which was misleading in one of the two cases.

This splits the conditional check into two parts with
distinct error messages and fixes the logic error.

Fixes the bug in

  commit 5184f398b40a5e0d7d84b86182edcb2b48ab04ba
  Author: Peter Krempa <pkrempa@redhat.com>
  Date:   Fri Jul 1 14:56:14 2016 +0200

    qemu: Store vCPU thread ids in vcpu private data objects

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit ed1fbd7c5ba90ce10cb9a7e35f32a4b4354988aa)
---
 src/qemu/qemu_domain.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 38225b5..1148b52 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1510,10 +1510,15 @@ qemuDomainObjPrivateXMLParseVcpu(xmlNodePtr node,
 
     idstr = virXMLPropString(node, "id");
 
-    if ((idstr && virStrToLong_uip(idstr, NULL, 10, &idx)) < 0 ||
-        !(vcpu = virDomainDefGetVcpu(def, idx))) {
+    if (idstr &&
+        (virStrToLong_uip(idstr, NULL, 10, &idx) < 0)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("invalid vcpu index '%s'"), idstr);
+                       _("cannot parse vcpu index '%s'"), idstr);
+        goto cleanup;
+    }
+    if (!(vcpu = virDomainDefGetVcpu(def, idx))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("invalid vcpu index '%u'"), idx);
         goto cleanup;
     }
 
-- 
2.10.0