From bb5ed814786f3148d1e54e26e9be10ea332c3058 Mon Sep 17 00:00:00 2001 Message-Id: From: Peter Krempa Date: Thu, 22 Jan 2015 15:53:52 +0100 Subject: [PATCH] conf: Avoid false positive of uninitialized variable use https://bugzilla.redhat.com/show_bug.cgi?id=1184929 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. (cherry picked from commit 0d4f469c871fb5997bb24f192924163263445980) Signed-off-by: Jiri Denemark --- src/conf/domain_conf.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c4829ff..a2c0d6c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19043,7 +19043,7 @@ virDomainDefSetMetadata(virDomainDefPtr def, { xmlDocPtr doc = NULL; xmlNodePtr old; - xmlNodePtr new; + xmlNodePtr new = NULL; char *tmp; int ret = -1; @@ -19092,11 +19092,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; -- 2.2.1