diff options
author | Nathan Straz <nstraz@redhat.com> | 2009-06-23 14:26:32 -0400 |
---|---|---|
committer | Nathan Straz <nstraz@redhat.com> | 2009-06-23 14:26:32 -0400 |
commit | 84ab2045844cb0c22a839b5a7605217c5398ab2e (patch) | |
tree | e333cd5a0b4a2d93b0855f215a69a10ff10a3d7a /gxpd.c | |
parent | 58704a5ec28143401690fa94f7f9d3d495df409f (diff) | |
download | gxpp-84ab2045844cb0c22a839b5a7605217c5398ab2e.tar.gz gxpp-84ab2045844cb0c22a839b5a7605217c5398ab2e.tar.xz gxpp-84ab2045844cb0c22a839b5a7605217c5398ab2e.zip |
Fix a segfault if no nodes were found
The check for nodeset or null nodeset would short circuit
causing us to deference the null nodeset. Return early instead
so we can process the rest of the files.
Include the filename in the output.
Diffstat (limited to 'gxpd.c')
-rw-r--r-- | gxpd.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -100,15 +100,15 @@ gxpd(char *fn, const char *xpath_query, const char *prefix) xpath_query, fn); exit(1); } - if (obj->type != XPATH_NODESET || obj->nodesetval == NULL) { - fprintf(stderr, "XPath expression '%s' did not match a nodeset.\n", xpath_query); - exit(1); + /* return early if there were no nodes to remove */ + if (obj->type != XPATH_NODESET) return 1; + if (obj->nodesetval == NULL) return 1; + + for (i = 0; i < obj->nodesetval->nodeNr; i++) { + xmlUnlinkNode(obj->nodesetval->nodeTab[i]); + xmlFreeNode(obj->nodesetval->nodeTab[i]); } - for (i = 0; i < obj->nodesetval->nodeNr; i++) { - xmlUnlinkNode(obj->nodesetval->nodeTab[i]); - xmlFreeNode(obj->nodesetval->nodeTab[i]); - } - printf("Removed %d nodes\n", i); + printf("%d nodes removed from %s\n", i, fn); xmlXPathFreeObject(obj); xmlSaveFile(fn, doc); |