898951
From bb5ed814786f3148d1e54e26e9be10ea332c3058 Mon Sep 17 00:00:00 2001
898951
Message-Id: <bb5ed814786f3148d1e54e26e9be10ea332c3058@dist-git>
898951
From: Peter Krempa <pkrempa@redhat.com>
898951
Date: Thu, 22 Jan 2015 15:53:52 +0100
898951
Subject: [PATCH] conf: Avoid false positive of uninitialized variable use
898951
898951
https://bugzilla.redhat.com/show_bug.cgi?id=1184929
898951
898951
GCC 4.8.0+ whines about variable "new" being uninitialized since
898951
commit 73bfac0e7182a3abd. This is a false positive as the
898951
xmlFreeNode(new) statement can be only reached if new was actually
898951
allocated successfully.
898951
898951
  CC       conf/libvirt_conf_la-domain_conf.lo
898951
  conf/domain_conf.c: In function 'virDomainDefSetMetadata':
898951
  conf/domain_conf.c:18650:24: error: 'new' may be used uninitialized in this function [-Werror=maybe-uninitialized]
898951
               xmlFreeNode(new);
898951
898951
Reported independently by John Ferlan and Michal Privoznik.
898951
898951
(cherry picked from commit 0d4f469c871fb5997bb24f192924163263445980)
898951
898951
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
898951
---
898951
 src/conf/domain_conf.c | 9 +++------
898951
 1 file changed, 3 insertions(+), 6 deletions(-)
898951
898951
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
898951
index c4829ff..a2c0d6c 100644
898951
--- a/src/conf/domain_conf.c
898951
+++ b/src/conf/domain_conf.c
898951
@@ -19043,7 +19043,7 @@ virDomainDefSetMetadata(virDomainDefPtr def,
898951
 {
898951
     xmlDocPtr doc = NULL;
898951
     xmlNodePtr old;
898951
-    xmlNodePtr new;
898951
+    xmlNodePtr new = NULL;
898951
     char *tmp;
898951
     int ret = -1;
898951
 
898951
@@ -19092,11 +19092,8 @@ virDomainDefSetMetadata(virDomainDefPtr def,
898951
             xmlFreeNode(old);
898951
         }
898951
 
898951
-        /* just delete the metadata */
898951
-        if (!metadata)
898951
-            break;
898951
-
898951
-        if (!(xmlAddChild(def->metadata, new))) {
898951
+        if (new &&
898951
+            !(xmlAddChild(def->metadata, new))) {
898951
             xmlFreeNode(new);
898951
             virReportOOMError();
898951
             goto cleanup;
898951
-- 
898951
2.2.1
898951