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?
Any objections to the fix:
- ret->boolval = 0;
+ ret->boolval = val ? 1 : 0;
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.
Thanks,
Phil
_______________________________________________
xslt mailing list, project page http://xmlsoft.org/XSLT/
[email protected]
http://mail.gnome.org/mailman/listinfo/xslt