[xslt] boolval of node sets

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:

xmlXPathNewNodeSet(xmlNodePtr val) {
    xmlXPathObjectPtr ret;
    ret->boolval = 0;
    ret->nodesetval = xmlXPathNodeSetCreate(val);
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:

xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val) {
        cur->nodeMax *= 2;
        temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax *
        if (temp == NULL) {
            xmlXPathErrMemory(NULL, "growing nodeset\n");
        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.


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