]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Consolidate virXPathNodeSet()
authorDaniel Veillard <veillard@redhat.com>
Thu, 22 Oct 2009 08:32:15 +0000 (10:32 +0200)
committerDaniel Veillard <veillard@redhat.com>
Thu, 22 Oct 2009 08:33:52 +0000 (10:33 +0200)
virXPathNodeSet() could return -1 when doing an evaluation failure
due to xmlXPathEval() from libxml2 behaviour.
* src/util/xml.c: make sure we always return 0 unless the returned
  XPath type is of the wrong type (meaning the query passed didn't
  evaluate to a node set and code must be fixed)

src/util/xml.c

index 4118d2a1dc45c0c96a00c6fc31145b6795cb90e6..4fa443d4b204fe6c24e05cdaeac48fe3b08cc5fd 100644 (file)
@@ -490,11 +490,16 @@ virXPathNodeSet(virConnectPtr conn,
     relnode = ctxt->node;
     obj = xmlXPathEval(BAD_CAST xpath, ctxt);
     ctxt->node = relnode;
-    if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
-        (obj->nodesetval == NULL) || (obj->nodesetval->nodeNr < 0)) {
+    if (obj == NULL)
+        return(0);
+    if (obj->type != XPATH_NODESET) {
         xmlXPathFreeObject(obj);
         return (-1);
     }
+    if ((obj->nodesetval == NULL)  || (obj->nodesetval->nodeNr < 0)) {
+        xmlXPathFreeObject(obj);
+        return (0);
+    }
 
     ret = obj->nodesetval->nodeNr;
     if (list != NULL && ret) {