[libvirt] [PATCH] qemu: silence clang false positive

Eric Blake eblake at redhat.com
Fri Aug 5 15:14:03 UTC 2011


Our logic throws off analyzer tools:

ptr var = NULL;
if (flags == 0) flags = live ? _LIVE : _CONFIG;
if (flags & _LIVE) do stuff
if (flags & _CONFIG) var = non-null;
if (flags & _LIVE) do more stuff
else if (flags & _CONFIG) use var

the tools keep thinking that var can still be NULL in the last
if clause, adding the hint shuts them up.

* src/qemu/qemu_driver.c (qemuDomainSetBlkioParameters): Add a
static analysis hint.
---

Off-list, I confirmed with Alex that ccc-analyzer and clang are both
built on the same llvm compiler front end, and thus give the same
analysis.  And I reproduced the static analyzer false positive; this
is the proper fix.

 src/qemu/qemu_driver.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ce19be7..a8e4b78 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5679,6 +5679,9 @@ static int qemuDomainSetBlkioParameters(virDomainPtr dom,
             }
         }
     } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+        /* Clang can't see that if we get here, persistentDef was set.  */
+        sa_assert(persistentDef);
+
         for (i = 0; i < nparams; i++) {
             virTypedParameterPtr param = &params[i];

-- 
1.7.4.4




More information about the libvir-list mailing list