Re: [xslt] boolval of node sets
- From: Daniel Veillard <veillard redhat com>
- To: The Gnome XSLT library mailing-list <xslt gnome org>
- Subject: Re: [xslt] boolval of node sets
- Date: Fri, 5 Nov 2010 19:23:53 +0100
On Thu, Oct 28, 2010 at 02:22:52PM -0400, Phil Shafer wrote:
> Is this behavior just a bug or am I missing something? The
> XPath spec says boolean() requires "a node-set is true if and only if it is non-empty",
> but the xmlXPathNewNodeSet() and xmlXPathNewValueTree()
> functions hardcode the value to 0 and 1, respectively:
>
> xmlXPathObjectPtr
> xmlXPathNewNodeSet(xmlNodePtr val) {
> xmlXPathObjectPtr ret;
> ...
> ret->boolval = 0;
> ret->nodesetval = xmlXPathNodeSetCreate(val);
> ...
> xmlXPathObjectPtr
> xmlXPathNewValueTree(xmlNodePtr val) {
> xmlXPathObjectPtr ret;
> ...
> ret->boolval = 1;
> ret->user = (void *) val;
> ret->nodesetval = xmlXPathNodeSetCreate(val);
> ...
>
> It looks like xmlXPathNewValueTree() is always called
> with a non-NULL tree, but there are >20 places where
> xmlXPathNewNodeSet is called with NULL.
>
> Is the value of the boolval field updated elsewhere
> or is this a problem?
just that boolval is meant to carry an information which
is not what the boolean() value will return.
> Any objections to the fix:
>
> - ret->boolval = 0;
> + ret->boolval = val ? 1 : 0;
This is likely to break EXSLT, so no
> While I'm here: a minor bug in xmlXPathNodeSetAdd() can
> make invalid node sets if xmlRealloc fails:
>
> void
> xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val) {
> ...
> cur->nodeMax *= 2;
> temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax *
> sizeof(xmlNodePtr));
> if (temp == NULL) {
> xmlXPathErrMemory(NULL, "growing nodeset\n");
> return;
> }
> cur->nodeTab = temp;
> ...
>
> nodeMax is changed even if the realloc fails, so the next
> attempt to add will end in bad news. I'll submit this and
> a patch via bugzilla.
Ah right it's a bug, a libxml2 bug, I'm fixing this in git,
thanks,
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel veillard com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]