Fixing assorted potential problems raised by scan
* encoding.c parser.c relaxng.c runsuite.c tree.c xmlreader.c
xmlschemas.c: nothing really serious but better safe than sorry
diff --git a/encoding.c b/encoding.c
index ef54156..d48c757 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1414,7 +1414,7 @@
void
xmlRegisterCharEncodingHandler(xmlCharEncodingHandlerPtr handler) {
if (handlers == NULL) xmlInitCharEncodingHandlers();
- if (handler == NULL) {
+ if ((handler == NULL) || (handlers == NULL)) {
xmlEncodingErr(XML_I18N_NO_HANDLER,
"xmlRegisterCharEncodingHandler: NULL handler !\n", NULL);
return;
diff --git a/parser.c b/parser.c
index 4b41ab9..5337541 100644
--- a/parser.c
+++ b/parser.c
@@ -250,14 +250,15 @@
return;
if (ctxt != NULL)
ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED;
+
if (prefix == NULL)
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
- ctxt->errNo, XML_ERR_FATAL, NULL, 0,
+ XML_ERR_ATTRIBUTE_REDEFINED, XML_ERR_FATAL, NULL, 0,
(const char *) localname, NULL, NULL, 0, 0,
"Attribute %s redefined\n", localname);
else
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
- ctxt->errNo, XML_ERR_FATAL, NULL, 0,
+ XML_ERR_ATTRIBUTE_REDEFINED, XML_ERR_FATAL, NULL, 0,
(const char *) prefix, (const char *) localname,
NULL, 0, 0, "Attribute %s:%s redefined\n", prefix,
localname);
@@ -555,14 +556,20 @@
if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC))
schannel = ctxt->sax->serror;
}
- __xmlRaiseError(schannel,
+ if (ctxt != NULL) {
+ __xmlRaiseError(schannel,
ctxt->vctxt.error, ctxt->vctxt.userData,
ctxt, NULL, XML_FROM_DTD, error,
XML_ERR_ERROR, NULL, 0, (const char *) str1,
(const char *) str2, NULL, 0, 0,
msg, (const char *) str1, (const char *) str2);
- if (ctxt != NULL) {
ctxt->valid = 0;
+ } else {
+ __xmlRaiseError(schannel, NULL, NULL,
+ ctxt, NULL, XML_FROM_DTD, error,
+ XML_ERR_ERROR, NULL, 0, (const char *) str1,
+ (const char *) str2, NULL, 0, 0,
+ msg, (const char *) str1, (const char *) str2);
}
}
@@ -12500,7 +12507,9 @@
* Record in the parent context the number of entities replacement
* done when parsing that reference.
*/
- oldctxt->nbentities += ctxt->nbentities;
+ if (oldctxt != NULL)
+ oldctxt->nbentities += ctxt->nbentities;
+
/*
* Also record the size of the entity parsed
*/
diff --git a/relaxng.c b/relaxng.c
index ea739de..351f03a 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -5363,7 +5363,7 @@
} else {
xmlRngPErr(ctxt, node, XML_RNGP_CHOICE_CONTENT,
"expecting name, anyName, nsName or choice : got %s\n",
- node->name, NULL);
+ (node == NULL ? 'nothing' : node->name), NULL);
return (NULL);
}
if (ret != def) {
@@ -9442,7 +9442,11 @@
xmlRelaxNGFreeStates(ctxt, ctxt->states);
ctxt->states = NULL;
if (found == 0) {
- VALID_ERR2(XML_RELAXNG_ERR_INTEREXTRA, cur->name);
+ if (cur == NULL) {
+ VALID_ERR2(XML_RELAXNG_ERR_INTEREXTRA, 'noname');
+ } else {
+ VALID_ERR2(XML_RELAXNG_ERR_INTEREXTRA, cur->name);
+ }
ret = -1;
ctxt->state = oldstate;
goto done;
diff --git a/runsuite.c b/runsuite.c
index af8ee5e..e6545fb 100644
--- a/runsuite.c
+++ b/runsuite.c
@@ -307,7 +307,7 @@
* *
************************************************************************/
-static int
+static int
xsdIncorectTestCase(xmlNodePtr cur) {
xmlNodePtr test;
xmlBufferPtr buf;
@@ -319,7 +319,7 @@
if (cur == NULL) {
return(0);
}
-
+
test = getNext(cur, "./*");
if (test == NULL) {
test_log("Failed to find test in correct line %ld\n",
diff --git a/tree.c b/tree.c
index bce60d2..edca54e 100644
--- a/tree.c
+++ b/tree.c
@@ -1801,7 +1801,7 @@
cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr));
if (cur == NULL) {
if ((eatname == 1) &&
- ((node->doc == NULL) ||
+ ((node == NULL) || (node->doc == NULL) ||
(!(xmlDictOwns(node->doc->dict, name)))))
xmlFree((xmlChar *) name);
xmlTreeErrMemory("building attribute");
@@ -1861,8 +1861,8 @@
}
}
- if ((value != NULL) &&
- (xmlIsID((node == NULL) ? NULL : node->doc, node, cur) == 1))
+ if ((value != NULL) && (node != NULL) &&
+ (xmlIsID(node->doc, node, cur) == 1))
xmlAddID(NULL, node->doc, value, cur);
if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
@@ -7779,8 +7779,11 @@
}
}
/* Create. */
- ns->next = xmlNewNs(NULL, nsName, prefix);
- return (ns->next);
+ if (ns != NULL) {
+ ns->next = xmlNewNs(NULL, nsName, prefix);
+ return (ns->next);
+ }
+ return(NULL);
}
/*
diff --git a/xmlreader.c b/xmlreader.c
index 1e562c2..c2afac7 100644
--- a/xmlreader.c
+++ b/xmlreader.c
@@ -1436,7 +1436,7 @@
/*
* Cleanup of the old node
*/
- if ((reader->preserves == 0) &&
+ if ((oldnode != NULL) && (reader->preserves == 0) &&
#ifdef LIBXML_XINCLUDE_ENABLED
(reader->in_xinclude == 0) &&
#endif
diff --git a/xmlschemas.c b/xmlschemas.c
index 8db448c..e79d5a0 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -6797,7 +6797,7 @@
tmp->next = NULL;
if (wildc->nsSet == NULL)
wildc->nsSet = tmp;
- else
+ else if (lastNs != NULL)
lastNs->next = tmp;
lastNs = tmp;
}
@@ -23721,12 +23721,14 @@
parBind->dupls = bind->dupls;
bind->dupls = NULL;
}
- if (*parTable == NULL)
- *parTable = parBind;
- else {
- parBind->next = *parTable;
- *parTable = parBind;
- }
+ if (parTable != NULL) {
+ if (*parTable == NULL)
+ *parTable = parBind;
+ else {
+ parBind->next = *parTable;
+ *parTable = parBind;
+ }
+ }
}
next_binding: