]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Avoid false positive of uninitialized variable use
authorPeter Krempa <pkrempa@redhat.com>
Tue, 17 Sep 2013 11:27:58 +0000 (13:27 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 17 Sep 2013 11:57:32 +0000 (13:57 +0200)
GCC 4.8.0+ whines about variable "new" being uninitialized since
commit 73bfac0e7182a3abd. This is a false positive as the
xmlFreeNode(new) statement can be only reached if new was actually
allocated successfully.

  CC       conf/libvirt_conf_la-domain_conf.lo
  conf/domain_conf.c: In function 'virDomainDefSetMetadata':
  conf/domain_conf.c:18650:24: error: 'new' may be used uninitialized in this function [-Werror=maybe-uninitialized]
               xmlFreeNode(new);

Reported independently by John Ferlan and Michal Privoznik.

src/conf/domain_conf.c

index 60f25abd67a5138ac6943ff821b5c20b3e590695..e5fe9002419ce810fdc0919250f3fc39b17d3a34 100644 (file)
@@ -18598,7 +18598,7 @@ virDomainDefSetMetadata(virDomainDefPtr def,
 {
     xmlDocPtr doc = NULL;
     xmlNodePtr old;
-    xmlNodePtr new;
+    xmlNodePtr new = NULL;
     char *tmp;
     int ret = -1;
 
@@ -18647,11 +18647,8 @@ virDomainDefSetMetadata(virDomainDefPtr def,
             xmlFreeNode(old);
         }
 
-        /* just delete the metadata */
-        if (!metadata)
-            break;
-
-        if (!(xmlAddChild(def->metadata, new))) {
+        if (new &&
+            !(xmlAddChild(def->metadata, new))) {
             xmlFreeNode(new);
             virReportOOMError();
             goto cleanup;