[libxml2] Fixing assorted potential problems raised by scan
- From: Daniel Veillard <veillard src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libxml2] Fixing assorted potential problems raised by scan
- Date: Mon, 7 Sep 2009 09:20:38 +0000 (UTC)
commit 76d364583ecb6a48bd4a4087f3cef9fc7838b481
Author: Daniel Veillard <veillard redhat com>
Date: Mon Sep 7 11:19:33 2009 +0200
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
encoding.c | 2 +-
parser.c | 19 ++++++++++++++-----
relaxng.c | 8 ++++++--
runsuite.c | 4 ++--
tree.c | 13 ++++++++-----
xmlreader.c | 2 +-
xmlschemas.c | 16 +++++++++-------
7 files changed, 41 insertions(+), 23 deletions(-)
---
diff --git a/encoding.c b/encoding.c
index ef54156..d48c757 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1414,7 +1414,7 @@ xmlCleanupCharEncodingHandlers(void) {
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 @@ xmlErrAttributeDup(xmlParserCtxtPtr ctxt, const xmlChar * prefix,
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 @@ xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error,
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 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
* 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 @@ xmlRelaxNGParseNameClass(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node,
} 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 @@ xmlRelaxNGValidateInterleave(xmlRelaxNGValidCtxtPtr ctxt,
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 @@ getString(xmlNodePtr cur, const char *xpath) {
* *
************************************************************************/
-static int
+static int
xsdIncorectTestCase(xmlNodePtr cur) {
xmlNodePtr test;
xmlBufferPtr buf;
@@ -319,7 +319,7 @@ xsdIncorectTestCase(xmlNodePtr cur) {
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 @@ xmlNewPropInternal(xmlNodePtr node, xmlNsPtr ns,
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 @@ xmlNewPropInternal(xmlNodePtr node, xmlNsPtr ns,
}
}
- 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 @@ xmlDOMWrapStoreNs(xmlDocPtr doc,
}
}
/* 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 @@ get_next_node:
/*
* 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 @@ xmlSchemaParseWildcardNs(xmlSchemaParserCtxtPtr ctxt,
tmp->next = NULL;
if (wildc->nsSet == NULL)
wildc->nsSet = tmp;
- else
+ else if (lastNs != NULL)
lastNs->next = tmp;
lastNs = tmp;
}
@@ -23721,12 +23721,14 @@ xmlSchemaBubbleIDCNodeTables(xmlSchemaValidCtxtPtr vctxt)
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:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]