From: Daniel Veillard Date: Thu, 22 Oct 2009 08:32:15 +0000 (+0200) Subject: Consolidate virXPathNodeSet() X-Git-Tag: v0.7.3~195 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f4682a9f8b76299a2c529d2aebc68f706e09ede;p=thirdparty%2Flibvirt.git Consolidate virXPathNodeSet() 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) --- diff --git a/src/util/xml.c b/src/util/xml.c index 4118d2a1dc..4fa443d4b2 100644 --- a/src/util/xml.c +++ b/src/util/xml.c @@ -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) {