1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

more coverage more fixes Daniel

* gentest.py testapi.c: more coverage
* debugXML.c parser.c xmlregexp.c xpath.c: more fixes
Daniel
This commit is contained in:
Daniel Veillard
2004-11-08 16:24:57 +00:00
parent 2a4fb5ac07
commit a82b182655
8 changed files with 6021 additions and 52 deletions

View File

@ -1,3 +1,8 @@
Mon Nov 8 17:25:27 CET 2004 Daniel Veillard <daniel@veillard.com>
* gentest.py testapi.c: more coverage
* debugXML.c parser.c xmlregexp.c xpath.c: more fixes
Mon Nov 8 15:02:39 CET 2004 Daniel Veillard <daniel@veillard.com> Mon Nov 8 15:02:39 CET 2004 Daniel Veillard <daniel@veillard.com>
* gentest.py testapi.c: more coverage * gentest.py testapi.c: more coverage

View File

@ -1151,6 +1151,7 @@ xmlCtxtDumpDocHead(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
static void static void
xmlCtxtDumpDocumentHead(xmlDebugCtxtPtr ctxt, xmlDocPtr doc) xmlCtxtDumpDocumentHead(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
{ {
if (doc == NULL) return;
xmlCtxtDumpDocHead(ctxt, doc); xmlCtxtDumpDocHead(ctxt, doc);
if (!ctxt->check) { if (!ctxt->check) {
if (doc->name != NULL) { if (doc->name != NULL) {
@ -1258,6 +1259,7 @@ xmlCtxtDumpEntityCallback(xmlEntityPtr cur, xmlDebugCtxtPtr ctxt)
static void static void
xmlCtxtDumpEntities(xmlDebugCtxtPtr ctxt, xmlDocPtr doc) xmlCtxtDumpEntities(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
{ {
if (doc == NULL) return;
xmlCtxtDumpDocHead(ctxt, doc); xmlCtxtDumpDocHead(ctxt, doc);
if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) { if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) {
xmlEntitiesTablePtr table = (xmlEntitiesTablePtr) xmlEntitiesTablePtr table = (xmlEntitiesTablePtr)
@ -1354,6 +1356,7 @@ void
xmlDebugDumpAttr(FILE *output, xmlAttrPtr attr, int depth) { xmlDebugDumpAttr(FILE *output, xmlAttrPtr attr, int depth) {
xmlDebugCtxt ctxt; xmlDebugCtxt ctxt;
if (output == NULL) return;
xmlCtxtDumpInitCtxt(&ctxt); xmlCtxtDumpInitCtxt(&ctxt);
ctxt.output = output; ctxt.output = output;
ctxt.depth = depth; ctxt.depth = depth;
@ -1374,6 +1377,7 @@ xmlDebugDumpEntities(FILE * output, xmlDocPtr doc)
{ {
xmlDebugCtxt ctxt; xmlDebugCtxt ctxt;
if (output == NULL) return;
xmlCtxtDumpInitCtxt(&ctxt); xmlCtxtDumpInitCtxt(&ctxt);
ctxt.output = output; ctxt.output = output;
xmlCtxtDumpEntities(&ctxt, doc); xmlCtxtDumpEntities(&ctxt, doc);
@ -1393,6 +1397,7 @@ xmlDebugDumpAttrList(FILE * output, xmlAttrPtr attr, int depth)
{ {
xmlDebugCtxt ctxt; xmlDebugCtxt ctxt;
if (output == NULL) return;
xmlCtxtDumpInitCtxt(&ctxt); xmlCtxtDumpInitCtxt(&ctxt);
ctxt.output = output; ctxt.output = output;
ctxt.depth = depth; ctxt.depth = depth;
@ -1413,6 +1418,7 @@ xmlDebugDumpOneNode(FILE * output, xmlNodePtr node, int depth)
{ {
xmlDebugCtxt ctxt; xmlDebugCtxt ctxt;
if (output == NULL) return;
xmlCtxtDumpInitCtxt(&ctxt); xmlCtxtDumpInitCtxt(&ctxt);
ctxt.output = output; ctxt.output = output;
ctxt.depth = depth; ctxt.depth = depth;
@ -1628,6 +1634,7 @@ xmlLsCountNode(xmlNodePtr node) {
*/ */
void void
xmlLsOneNode(FILE *output, xmlNodePtr node) { xmlLsOneNode(FILE *output, xmlNodePtr node) {
if (output == NULL) return;
if (node == NULL) { if (node == NULL) {
fprintf(output, "NULL\n"); fprintf(output, "NULL\n");
return; return;
@ -1834,9 +1841,11 @@ xmlShellPrintXPathError(int errorType, const char *arg)
"%s is an XSLT value tree\n", arg); "%s is an XSLT value tree\n", arg);
break; break;
} }
#if 0
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"Try casting the result string function (xpath builtin)\n", "Try casting the result string function (xpath builtin)\n",
arg); arg);
#endif
} }
@ -2391,6 +2400,7 @@ xmlShellLoad(xmlShellCtxtPtr ctxt, char *filename,
xmlDocPtr doc; xmlDocPtr doc;
int html = 0; int html = 0;
if ((ctxt == NULL) || (filename == NULL)) return(-1);
if (ctxt->doc != NULL) if (ctxt->doc != NULL)
html = (ctxt->doc->type == XML_HTML_DOCUMENT_NODE); html = (ctxt->doc->type == XML_HTML_DOCUMENT_NODE);
@ -2445,8 +2455,6 @@ xmlShellWrite(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node,
if (node == NULL) if (node == NULL)
return (-1); return (-1);
if ((filename == NULL) || (filename[0] == 0)) { if ((filename == NULL) || (filename[0] == 0)) {
xmlGenericError(xmlGenericErrorContext,
"Write command requires a filename argument\n");
return (-1); return (-1);
} }
#ifdef W_OK #ifdef W_OK
@ -2512,10 +2520,12 @@ xmlShellSave(xmlShellCtxtPtr ctxt, char *filename,
xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr node ATTRIBUTE_UNUSED,
xmlNodePtr node2 ATTRIBUTE_UNUSED) xmlNodePtr node2 ATTRIBUTE_UNUSED)
{ {
if (ctxt->doc == NULL) if ((ctxt == NULL) || (ctxt->doc == NULL))
return (-1); return (-1);
if ((filename == NULL) || (filename[0] == 0)) if ((filename == NULL) || (filename[0] == 0))
filename = ctxt->filename; filename = ctxt->filename;
if (filename == NULL)
return (-1);
#ifdef W_OK #ifdef W_OK
if (access((char *) filename, W_OK)) { if (access((char *) filename, W_OK)) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
@ -2575,6 +2585,7 @@ xmlShellValidate(xmlShellCtxtPtr ctxt, char *dtd,
xmlValidCtxt vctxt; xmlValidCtxt vctxt;
int res = -1; int res = -1;
if ((ctxt == NULL) || (ctxt->doc == NULL)) return(-1);
vctxt.userData = stderr; vctxt.userData = stderr;
vctxt.error = (xmlValidityErrorFunc) fprintf; vctxt.error = (xmlValidityErrorFunc) fprintf;
vctxt.warning = (xmlValidityWarningFunc) fprintf; vctxt.warning = (xmlValidityWarningFunc) fprintf;
@ -2697,7 +2708,7 @@ xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer,
{ {
xmlChar *path; xmlChar *path;
if (node == NULL) if ((node == NULL) || (buffer == NULL))
return (-1); return (-1);
path = xmlGetNodePath(node); path = xmlGetNodePath(node);
@ -2873,7 +2884,11 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
} else if (!strcmp(command, "save")) { } else if (!strcmp(command, "save")) {
xmlShellSave(ctxt, arg, NULL, NULL); xmlShellSave(ctxt, arg, NULL, NULL);
} else if (!strcmp(command, "write")) { } else if (!strcmp(command, "write")) {
xmlShellWrite(ctxt, arg, NULL, NULL); if ((arg == NULL) || (arg[0] == 0))
xmlGenericError(xmlGenericErrorContext,
"Write command requires a filename argument\n");
else
xmlShellWrite(ctxt, arg, NULL, NULL);
#endif /* LIBXML_OUTPUT_ENABLED */ #endif /* LIBXML_OUTPUT_ENABLED */
} else if (!strcmp(command, "grep")) { } else if (!strcmp(command, "grep")) {
xmlShellGrep(ctxt, arg, ctxt->node, NULL); xmlShellGrep(ctxt, arg, ctxt->node, NULL);

View File

@ -15,12 +15,9 @@ except:
# Modules we don't want skip in API test # Modules we don't want skip in API test
# #
skipped_modules = [ "SAX", "xlink", "threads", "globals", skipped_modules = [ "SAX", "xlink", "threads", "globals",
"xpathInternals", "xmlmemory", "xmlmemory", "xmlversion", "xmlexports",
"xmlversion", "debugXML", "xmlexports", "DOCBparser", #deprecated
"DOCBparser",
# temporary
"xmlautomata", "xmlregexp", "c14n",
] ]
# #
@ -46,6 +43,7 @@ skipped_functions = [
"xmlSetTreeDoc", "xmlUnlinkNode", "xmlSetTreeDoc", "xmlUnlinkNode",
# hard to avoid leaks in the tests # hard to avoid leaks in the tests
"xmlStrcat", "xmlStrncat", "xmlCatalogAddLocal", "xmlNewTextWriterDoc", "xmlStrcat", "xmlStrncat", "xmlCatalogAddLocal", "xmlNewTextWriterDoc",
"xmlXPathNewValueTree", "xmlXPathWrapString",
# unimplemented # unimplemented
"xmlTextReaderReadInnerXml", "xmlTextReaderReadOuterXml", "xmlTextReaderReadInnerXml", "xmlTextReaderReadOuterXml",
"xmlTextReaderReadString", "xmlTextReaderReadString",
@ -57,10 +55,11 @@ skipped_functions = [
"xmlNamespaceParseNSDef", "xmlNamespaceParseQName", "xmlNamespaceParseNSDef", "xmlNamespaceParseQName",
"xmlParseNamespace", "xmlParseQuotedString", "xmlParserHandleReference", "xmlParseNamespace", "xmlParseQuotedString", "xmlParserHandleReference",
"xmlScanName", "xmlScanName",
"xmlDecodeEntities",
# allocators # allocators
"xmlMemFree", "xmlMemFree",
# verbosity # verbosity
"xmlCatalogSetDebug", "xmlCatalogSetDebug", "xmlShellPrintXPathError", "xmlShellPrintNode",
# Internal functions, no user space should really call them # Internal functions, no user space should really call them
"xmlParseAttribute", "xmlParseAttributeListDecl", "xmlParseName", "xmlParseAttribute", "xmlParseAttributeListDecl", "xmlParseName",
"xmlParseNmtoken", "xmlParseEntityValue", "xmlParseAttValue", "xmlParseNmtoken", "xmlParseEntityValue", "xmlParseAttValue",
@ -277,6 +276,8 @@ def type_convert(str, name, info, module, function, pos):
res = 'const_xmlChar_ptr_ptr' res = 'const_xmlChar_ptr_ptr'
if res == 'const_char_ptr*': if res == 'const_char_ptr*':
res = 'const_char_ptr_ptr' res = 'const_char_ptr_ptr'
if res == 'FILE_ptr' and module == 'debugXML':
res = 'debug_FILE_ptr';
return res return res

View File

@ -40,7 +40,7 @@ extern "C" {
*/ */
#define xmlXPathSetError(ctxt, err) \ #define xmlXPathSetError(ctxt, err) \
{ xmlXPatherror((ctxt), __FILE__, __LINE__, (err)); \ { xmlXPatherror((ctxt), __FILE__, __LINE__, (err)); \
(ctxt)->error = (err); } if ((ctxt) != NULL) (ctxt)->error = (err); }
/** /**
* xmlXPathSetArityError: * xmlXPathSetArityError:
@ -294,6 +294,7 @@ XMLPUBFUN void * XMLCALL
* Macro to check that the number of args passed to an XPath function matches. * Macro to check that the number of args passed to an XPath function matches.
*/ */
#define CHECK_ARITY(x) \ #define CHECK_ARITY(x) \
if (ctxt == NULL) return; \
if (nargs != (x)) \ if (nargs != (x)) \
XP_ERROR(XPATH_INVALID_ARITY); XP_ERROR(XPATH_INVALID_ARITY);

View File

@ -1420,7 +1420,7 @@ xmlSkipBlankChars(xmlParserCtxtPtr ctxt) {
*/ */
xmlChar xmlChar
xmlPopInput(xmlParserCtxtPtr ctxt) { xmlPopInput(xmlParserCtxtPtr ctxt) {
if (ctxt->inputNr <= 1) return(0); /* End of main Input */ if ((ctxt == NULL) || (ctxt->inputNr <= 1)) return(0);
if (xmlParserDebugEntities) if (xmlParserDebugEntities)
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"Popping input %d\n", ctxt->inputNr); "Popping input %d\n", ctxt->inputNr);
@ -1934,7 +1934,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
int c,l; int c,l;
int nbchars = 0; int nbchars = 0;
if ((str == NULL) || (len < 0)) if ((ctxt == NULL) || (str == NULL) || (len < 0))
return(NULL); return(NULL);
last = str + len; last = str + len;
@ -2076,6 +2076,7 @@ mem_error:
xmlChar * xmlChar *
xmlStringDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int what, xmlStringDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int what,
xmlChar end, xmlChar end2, xmlChar end3) { xmlChar end, xmlChar end2, xmlChar end3) {
if ((ctxt == NULL) || (str == NULL)) return(NULL);
return(xmlStringLenDecodeEntities(ctxt, str, xmlStrlen(str), what, return(xmlStringLenDecodeEntities(ctxt, str, xmlStrlen(str), what,
end, end2, end3)); end, end2, end3));
} }

5968
testapi.c

File diff suppressed because it is too large Load Diff

View File

@ -4062,6 +4062,8 @@ void
xmlRegexpPrint(FILE *output, xmlRegexpPtr regexp) { xmlRegexpPrint(FILE *output, xmlRegexpPtr regexp) {
int i; int i;
if (output == NULL)
return;
fprintf(output, " regexp: "); fprintf(output, " regexp: ");
if (regexp == NULL) { if (regexp == NULL) {
fprintf(output, "NULL\n"); fprintf(output, "NULL\n");

50
xpath.c
View File

@ -775,6 +775,8 @@ xmlXPathDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth) {
int i; int i;
char shift[100]; char shift[100];
if (output == NULL) return;
for (i = 0;((i < depth) && (i < 25));i++) for (i = 0;((i < depth) && (i < 25));i++)
shift[2 * i] = shift[2 * i + 1] = ' '; shift[2 * i] = shift[2 * i + 1] = ' ';
shift[2 * i] = shift[2 * i + 1] = 0; shift[2 * i] = shift[2 * i + 1] = 0;
@ -1063,6 +1065,8 @@ xmlXPathDebugDumpCompExpr(FILE *output, xmlXPathCompExprPtr comp,
int i; int i;
char shift[100]; char shift[100];
if ((output == NULL) || (comp == NULL)) return;
for (i = 0;((i < depth) && (i < 25));i++) for (i = 0;((i < depth) && (i < 25));i++)
shift[2 * i] = shift[2 * i + 1] = ' '; shift[2 * i] = shift[2 * i + 1] = ' ';
shift[2 * i] = shift[2 * i + 1] = 0; shift[2 * i] = shift[2 * i + 1] = 0;
@ -1099,7 +1103,7 @@ valuePop(xmlXPathParserContextPtr ctxt)
{ {
xmlXPathObjectPtr ret; xmlXPathObjectPtr ret;
if (ctxt->valueNr <= 0) if ((ctxt == NULL) || (ctxt->valueNr <= 0))
return (0); return (0);
ctxt->valueNr--; ctxt->valueNr--;
if (ctxt->valueNr > 0) if (ctxt->valueNr > 0)
@ -1122,6 +1126,7 @@ valuePop(xmlXPathParserContextPtr ctxt)
extern int extern int
valuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr value) valuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr value)
{ {
if ((ctxt == NULL) || (value == NULL)) return(-1);
if (ctxt->valueNr >= ctxt->valueMax) { if (ctxt->valueNr >= ctxt->valueMax) {
xmlXPathObjectPtr *tmp; xmlXPathObjectPtr *tmp;
@ -1268,7 +1273,7 @@ xmlXPathPopExternal (xmlXPathParserContextPtr ctxt) {
xmlXPathObjectPtr obj; xmlXPathObjectPtr obj;
void * ret; void * ret;
if (ctxt->value == NULL) { if ((ctxt == NULL) || (ctxt->value == NULL)) {
xmlXPathSetError(ctxt, XPATH_INVALID_OPERAND); xmlXPathSetError(ctxt, XPATH_INVALID_OPERAND);
return(NULL); return(NULL);
} }
@ -1803,6 +1808,7 @@ int
xmlXPathNodeSetContains (xmlNodeSetPtr cur, xmlNodePtr val) { xmlXPathNodeSetContains (xmlNodeSetPtr cur, xmlNodePtr val) {
int i; int i;
if ((cur == NULL) || (val == NULL)) return(0);
if (val->type == XML_NAMESPACE_DECL) { if (val->type == XML_NAMESPACE_DECL) {
for (i = 0; i < cur->nodeNr; i++) { for (i = 0; i < cur->nodeNr; i++) {
if (cur->nodeTab[i]->type == XML_NAMESPACE_DECL) { if (cur->nodeTab[i]->type == XML_NAMESPACE_DECL) {
@ -1838,7 +1844,9 @@ void
xmlXPathNodeSetAddNs(xmlNodeSetPtr cur, xmlNodePtr node, xmlNsPtr ns) { xmlXPathNodeSetAddNs(xmlNodeSetPtr cur, xmlNodePtr node, xmlNsPtr ns) {
int i; int i;
if ((ns == NULL) || (node == NULL) || (ns->type != XML_NAMESPACE_DECL) ||
if ((cur == NULL) || (ns == NULL) || (node == NULL) ||
(ns->type != XML_NAMESPACE_DECL) ||
(node->type != XML_ELEMENT_NODE)) (node->type != XML_ELEMENT_NODE))
return; return;
@ -1893,7 +1901,7 @@ void
xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val) { xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val) {
int i; int i;
if (val == NULL) return; if ((cur == NULL) || (val == NULL)) return;
#if 0 #if 0
if ((val->type == XML_ELEMENT_NODE) && (val->name[0] == ' ')) if ((val->type == XML_ELEMENT_NODE) && (val->name[0] == ' '))
@ -1951,7 +1959,7 @@ xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val) {
*/ */
void void
xmlXPathNodeSetAddUnique(xmlNodeSetPtr cur, xmlNodePtr val) { xmlXPathNodeSetAddUnique(xmlNodeSetPtr cur, xmlNodePtr val) {
if (val == NULL) return; if ((cur == NULL) || (val == NULL)) return;
#if 0 #if 0
if ((val->type == XML_ELEMENT_NODE) && (val->name[0] == ' ')) if ((val->type == XML_ELEMENT_NODE) && (val->name[0] == ' '))
@ -4859,6 +4867,7 @@ xmlXPathEqualValues(xmlXPathParserContextPtr ctxt) {
xmlXPathObjectPtr arg1, arg2, argtmp; xmlXPathObjectPtr arg1, arg2, argtmp;
int ret = 0; int ret = 0;
if ((ctxt == NULL) || (ctxt->context == NULL)) return;
arg2 = valuePop(ctxt); arg2 = valuePop(ctxt);
arg1 = valuePop(ctxt); arg1 = valuePop(ctxt);
if ((arg1 == NULL) || (arg2 == NULL)) { if ((arg1 == NULL) || (arg2 == NULL)) {
@ -4942,6 +4951,7 @@ xmlXPathNotEqualValues(xmlXPathParserContextPtr ctxt) {
xmlXPathObjectPtr arg1, arg2, argtmp; xmlXPathObjectPtr arg1, arg2, argtmp;
int ret = 0; int ret = 0;
if ((ctxt == NULL) || (ctxt->context == NULL)) return;
arg2 = valuePop(ctxt); arg2 = valuePop(ctxt);
arg1 = valuePop(ctxt); arg1 = valuePop(ctxt);
if ((arg1 == NULL) || (arg2 == NULL)) { if ((arg1 == NULL) || (arg2 == NULL)) {
@ -5041,6 +5051,7 @@ xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict) {
int ret = 0, arg1i = 0, arg2i = 0; int ret = 0, arg1i = 0, arg2i = 0;
xmlXPathObjectPtr arg1, arg2; xmlXPathObjectPtr arg1, arg2;
if ((ctxt == NULL) || (ctxt->context == NULL)) return;
arg2 = valuePop(ctxt); arg2 = valuePop(ctxt);
arg1 = valuePop(ctxt); arg1 = valuePop(ctxt);
if ((arg1 == NULL) || (arg2 == NULL)) { if ((arg1 == NULL) || (arg2 == NULL)) {
@ -5152,6 +5163,7 @@ xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict) {
*/ */
void void
xmlXPathValueFlipSign(xmlXPathParserContextPtr ctxt) { xmlXPathValueFlipSign(xmlXPathParserContextPtr ctxt) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return;
CAST_TO_NUMBER; CAST_TO_NUMBER;
CHECK_TYPE(XPATH_NUMBER); CHECK_TYPE(XPATH_NUMBER);
if (xmlXPathIsNaN(ctxt->value->floatval)) if (xmlXPathIsNaN(ctxt->value->floatval))
@ -5339,6 +5351,7 @@ typedef xmlNodePtr (*xmlXPathTraversalFunction)
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if (cur == NULL) if (cur == NULL)
return(ctxt->context->node); return(ctxt->context->node);
return(NULL); return(NULL);
@ -5356,6 +5369,7 @@ xmlXPathNextSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextChild(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextChild(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if (cur == NULL) { if (cur == NULL) {
if (ctxt->context->node == NULL) return(NULL); if (ctxt->context->node == NULL) return(NULL);
switch (ctxt->context->node->type) { switch (ctxt->context->node->type) {
@ -5407,6 +5421,7 @@ xmlXPathNextChild(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if (cur == NULL) { if (cur == NULL) {
if (ctxt->context->node == NULL) if (ctxt->context->node == NULL)
return(NULL); return(NULL);
@ -5469,6 +5484,7 @@ xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextDescendantOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextDescendantOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if (cur == NULL) { if (cur == NULL) {
if (ctxt->context->node == NULL) if (ctxt->context->node == NULL)
return(NULL); return(NULL);
@ -5493,6 +5509,7 @@ xmlXPathNextDescendantOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextParent(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextParent(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
/* /*
* the parent of an attribute or namespace node is the element * the parent of an attribute or namespace node is the element
* to which the attribute or namespace node is attached * to which the attribute or namespace node is attached
@ -5565,6 +5582,7 @@ xmlXPathNextParent(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
/* /*
* the parent of an attribute or namespace node is the element * the parent of an attribute or namespace node is the element
* to which the attribute or namespace node is attached * to which the attribute or namespace node is attached
@ -5688,6 +5706,7 @@ xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextAncestorOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextAncestorOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if (cur == NULL) if (cur == NULL)
return(ctxt->context->node); return(ctxt->context->node);
return(xmlXPathNextAncestor(ctxt, cur)); return(xmlXPathNextAncestor(ctxt, cur));
@ -5706,6 +5725,7 @@ xmlXPathNextAncestorOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextFollowingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextFollowingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) || if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) ||
(ctxt->context->node->type == XML_NAMESPACE_DECL)) (ctxt->context->node->type == XML_NAMESPACE_DECL))
return(NULL); return(NULL);
@ -5730,6 +5750,7 @@ xmlXPathNextFollowingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) || if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) ||
(ctxt->context->node->type == XML_NAMESPACE_DECL)) (ctxt->context->node->type == XML_NAMESPACE_DECL))
return(NULL); return(NULL);
@ -5760,6 +5781,7 @@ xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextFollowing(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextFollowing(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if (cur != NULL && cur->children != NULL) if (cur != NULL && cur->children != NULL)
return cur->children ; return cur->children ;
if (cur == NULL) cur = ctxt->context->node; if (cur == NULL) cur = ctxt->context->node;
@ -5815,6 +5837,7 @@ xmlXPathIsAncestor(xmlNodePtr ancestor, xmlNodePtr node) {
xmlNodePtr xmlNodePtr
xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt, xmlNodePtr cur)
{ {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if (cur == NULL) if (cur == NULL)
cur = ctxt->context->node; cur = ctxt->context->node;
if (cur == NULL) if (cur == NULL)
@ -5855,6 +5878,7 @@ static xmlNodePtr
xmlXPathNextPrecedingInternal(xmlXPathParserContextPtr ctxt, xmlXPathNextPrecedingInternal(xmlXPathParserContextPtr ctxt,
xmlNodePtr cur) xmlNodePtr cur)
{ {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if (cur == NULL) { if (cur == NULL) {
cur = ctxt->context->node; cur = ctxt->context->node;
if (cur == NULL) if (cur == NULL)
@ -5897,6 +5921,7 @@ xmlXPathNextPrecedingInternal(xmlXPathParserContextPtr ctxt,
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if (ctxt->context->node->type != XML_ELEMENT_NODE) return(NULL); if (ctxt->context->node->type != XML_ELEMENT_NODE) return(NULL);
if (ctxt->context->tmpNsList == NULL && cur != (xmlNodePtr) xmlXPathXMLNamespace) { if (ctxt->context->tmpNsList == NULL && cur != (xmlNodePtr) xmlXPathXMLNamespace) {
if (ctxt->context->tmpNsList != NULL) if (ctxt->context->tmpNsList != NULL)
@ -5933,6 +5958,7 @@ xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
*/ */
xmlNodePtr xmlNodePtr
xmlXPathNextAttribute(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { xmlXPathNextAttribute(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if (ctxt->context->node == NULL) if (ctxt->context->node == NULL)
return(NULL); return(NULL);
if (ctxt->context->node->type != XML_ELEMENT_NODE) if (ctxt->context->node->type != XML_ELEMENT_NODE)
@ -5968,6 +5994,7 @@ xmlXPathNextAttribute(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
*/ */
void void
xmlXPathRoot(xmlXPathParserContextPtr ctxt) { xmlXPathRoot(xmlXPathParserContextPtr ctxt) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return;
ctxt->context->node = (xmlNodePtr) ctxt->context->doc; ctxt->context->node = (xmlNodePtr) ctxt->context->doc;
valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node)); valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node));
} }
@ -6204,6 +6231,8 @@ void
xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs) { xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlXPathObjectPtr cur; xmlXPathObjectPtr cur;
if (ctxt == NULL) return;
if (nargs == 0) { if (nargs == 0) {
valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node)); valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node));
nargs = 1; nargs = 1;
@ -6259,6 +6288,8 @@ void
xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs) { xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlXPathObjectPtr cur; xmlXPathObjectPtr cur;
if (ctxt == NULL) return;
if (nargs == 0) { if (nargs == 0) {
valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node)); valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node));
nargs = 1; nargs = 1;
@ -6408,6 +6439,7 @@ void
xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs) { xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlXPathObjectPtr cur; xmlXPathObjectPtr cur;
if (ctxt == NULL) return;
if (nargs == 0) { if (nargs == 0) {
valuePush(ctxt, valuePush(ctxt,
xmlXPathWrapString( xmlXPathWrapString(
@ -6439,6 +6471,8 @@ xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlXPathObjectPtr cur; xmlXPathObjectPtr cur;
if (nargs == 0) { if (nargs == 0) {
if ((ctxt == NULL) || (ctxt->context == NULL))
return;
if (ctxt->context->node == NULL) { if (ctxt->context->node == NULL) {
valuePush(ctxt, xmlXPathNewFloat(0)); valuePush(ctxt, xmlXPathNewFloat(0));
} else { } else {
@ -6472,6 +6506,7 @@ xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlXPathObjectPtr cur, newobj; xmlXPathObjectPtr cur, newobj;
xmlChar *tmp; xmlChar *tmp;
if (ctxt == NULL) return;
if (nargs < 2) { if (nargs < 2) {
CHECK_ARITY(2); CHECK_ARITY(2);
} }
@ -6803,6 +6838,7 @@ xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlBufferPtr target; xmlBufferPtr target;
xmlChar blank; xmlChar blank;
if (ctxt == NULL) return;
if (nargs == 0) { if (nargs == 0) {
/* Use current context node */ /* Use current context node */
valuePush(ctxt, valuePush(ctxt,
@ -7058,6 +7094,7 @@ xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlXPathObjectPtr cur; xmlXPathObjectPtr cur;
double res; double res;
if (ctxt == NULL) return;
if (nargs == 0) { if (nargs == 0) {
if (ctxt->context->node == NULL) { if (ctxt->context->node == NULL) {
valuePush(ctxt, xmlXPathNewFloat(0.0)); valuePush(ctxt, xmlXPathNewFloat(0.0));
@ -7335,6 +7372,7 @@ xmlXPathParseNCName(xmlXPathParserContextPtr ctxt) {
xmlChar *ret; xmlChar *ret;
int count = 0; int count = 0;
if ((ctxt == NULL) || (ctxt->cur == NULL)) return(NULL);
/* /*
* Accelerator for simple ASCII names * Accelerator for simple ASCII names
*/ */
@ -7415,6 +7453,7 @@ xmlXPathParseName(xmlXPathParserContextPtr ctxt) {
xmlChar *ret; xmlChar *ret;
int count = 0; int count = 0;
if ((ctxt == NULL) || (ctxt->cur == NULL)) return(NULL);
/* /*
* Accelerator for simple ASCII names * Accelerator for simple ASCII names
*/ */
@ -11128,6 +11167,7 @@ xmlXPathCompiledEval(xmlXPathCompExprPtr comp, xmlXPathContextPtr ctx) {
*/ */
void void
xmlXPathEvalExpr(xmlXPathParserContextPtr ctxt) { xmlXPathEvalExpr(xmlXPathParserContextPtr ctxt) {
if (ctxt == NULL) return;
xmlXPathCompileExpr(ctxt); xmlXPathCompileExpr(ctxt);
CHECK_ERROR; CHECK_ERROR;
xmlXPathRunEval(ctxt); xmlXPathRunEval(ctxt);