[PATCH 11/43] testParseXMLDocFromFile: Refactor control flow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Move few variables definitions closer to usage, add comments explaining
what's happening and simplify the control flow.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/test/test_driver.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 1c10124564..5740f54a58 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -841,32 +841,34 @@ testDomainObjCheckTaint(virDomainObj *obj)
 }

 static xmlNodePtr
-testParseXMLDocFromFile(xmlNodePtr node, const char *file, const char *type)
+testParseXMLDocFromFile(xmlNodePtr node,
+                        const char *file,
+                        const char *type)
 {
-    xmlNodePtr ret = NULL;
     g_autoptr(xmlDoc) doc = NULL;
-    g_autofree char *absFile = NULL;
     g_autofree char *relFile = NULL;

     if ((relFile = virXMLPropString(node, "file"))) {
-        absFile = testBuildFilename(file, relFile);
+        g_autofree char *absFile = testBuildFilename(file, relFile);
+        xmlNodePtr newnode = NULL;

         if (!(doc = virXMLParse(absFile, NULL, type, NULL, NULL, NULL, false)))
             return NULL;

-        ret = xmlCopyNode(xmlDocGetRootElement(doc), 1);
-        if (!ret) {
+        if (!(newnode = xmlCopyNode(xmlDocGetRootElement(doc), 1))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Failed to copy XML node"));
             return NULL;
         }
-        xmlReplaceNode(node, ret);
+
+        /* place 'newnode' in place of 'node' in the original XML document object */
+        xmlReplaceNode(node, newnode);
+        /* free the original node */
         xmlFreeNode(node);
-    } else {
-        ret = node;
+        return newnode;
     }

-    return ret;
+    return node;
 }

 static int
-- 
2.37.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux