aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--HTMLparser.c9
-rw-r--r--NEWS7
-rw-r--r--parser.c121
-rw-r--r--parserInternals.c28
-rw-r--r--pattern.c6
-rw-r--r--uri.c10
7 files changed, 99 insertions, 87 deletions
diff --git a/ChangeLog b/ChangeLog
index 1904ba4d..1e667ccb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Mar 9 15:12:19 CET 2006 Daniel Veillard <daniel@veillard.com>
+
+ * HTMLparser.c parser.c parserInternals.c pattern.c uri.c: a bunch
+ of small cleanups based on coverity reports.
+
Thu Mar 9 09:42:10 CET 2006 Daniel Veillard <daniel@veillard.com>
* win32/Makefile.bcb: added schematron as pointed out by Eric Zurcher
diff --git a/HTMLparser.c b/HTMLparser.c
index 5cbc9040..2e646ad2 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -3389,9 +3389,9 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
const xmlChar *name;
const xmlChar *attname;
xmlChar *attvalue;
- const xmlChar **atts = ctxt->atts;
+ const xmlChar **atts;
int nbatts = 0;
- int maxatts = ctxt->maxatts;
+ int maxatts;
int meta = 0;
int i;
@@ -3403,6 +3403,9 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
if (CUR != '<') return -1;
NEXT;
+ atts = ctxt->atts;
+ maxatts = ctxt->maxatts;
+
GROW;
name = htmlParseHTMLName(ctxt);
if (name == NULL) {
@@ -3963,7 +3966,7 @@ htmlParseElement(htmlParserCtxtPtr ctxt) {
/*
* Capture end position and add node
*/
- if ( currentNode != NULL && ctxt->record_info ) {
+ if (ctxt->record_info) {
node_info.end_pos = ctxt->input->consumed +
(CUR_PTR - ctxt->input->base);
node_info.end_line = ctxt->input->line;
diff --git a/NEWS b/NEWS
index ccb9ace8..156e97a3 100644
--- a/NEWS
+++ b/NEWS
@@ -21,8 +21,8 @@ http://cvs.gnome.org/viewcvs/libxml2/
--with-minimum compilation fixes (William Brack), error case handling fix
on Solaris (Albert Chin), don't use 'list' as parameter name reported by
Samuel Diaz Garcia, more old Unices portability fixes (Albert Chin),
- MinGW compilation (Mark Junker), HP-UX compiler warnings (Rick Jones),
-
+ MinGW compilation (Mark Junker), HP-UX compiler warnings (Rick
+ Jones),
- code cleanup: xmlReportError (Adrian Mouat), remove xmlBufferClose
(Geert Jansen), unreachable code (Oleksandr Kononenko), refactoring
parsing code (Bjorn Reese)
@@ -55,10 +55,9 @@ http://cvs.gnome.org/viewcvs/libxml2/
standalone attribute was found, add xmlSchemaSetParserStructuredErrors()
(Kasimier Buchcik), add xmlTextReaderSchemaValidateCtxt() to API
(Kasimier), handle gzipped HTTP resources (Gary Coady), add
- htmlDocDumpMemoryFormat. (Rob Richards),
+ htmlDocDumpMemoryFormat. (Rob Richards),
- documentation: typo (Michael Day), libxml man page (Albert Chin), save
function to XML buffer (Geert Jansen), small doc fix (Aron Stansvik),
-
2.6.22: Sep 12 2005:
diff --git a/parser.c b/parser.c
index 8ffe2c22..d3c8e5e0 100644
--- a/parser.c
+++ b/parser.c
@@ -147,7 +147,8 @@ xmlErrAttributeDup(xmlParserCtxtPtr ctxt, const xmlChar * prefix,
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
- ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED;
+ 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,
@@ -159,9 +160,11 @@ xmlErrAttributeDup(xmlParserCtxtPtr ctxt, const xmlChar * prefix,
(const char *) prefix, (const char *) localname,
NULL, 0, 0, "Attribute %s:%s redefined\n", prefix,
localname);
- ctxt->wellFormed = 0;
- if (ctxt->recovery == 0)
- ctxt->disableSAX = 1;
+ if (ctxt != NULL) {
+ ctxt->wellFormed = 0;
+ if (ctxt->recovery == 0)
+ ctxt->disableSAX = 1;
+ }
}
/**
@@ -359,13 +362,16 @@ xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
default:
errmsg = "Unregistered error message\n";
}
- ctxt->errNo = error;
+ if (ctxt != NULL)
+ ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, errmsg,
info);
- ctxt->wellFormed = 0;
- if (ctxt->recovery == 0)
- ctxt->disableSAX = 1;
+ if (ctxt != NULL) {
+ ctxt->wellFormed = 0;
+ if (ctxt->recovery == 0)
+ ctxt->disableSAX = 1;
+ }
}
/**
@@ -383,12 +389,15 @@ xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
- ctxt->errNo = error;
+ if (ctxt != NULL)
+ ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, msg);
- ctxt->wellFormed = 0;
- if (ctxt->recovery == 0)
- ctxt->disableSAX = 1;
+ if (ctxt != NULL) {
+ ctxt->wellFormed = 0;
+ if (ctxt->recovery == 0)
+ ctxt->disableSAX = 1;
+ }
}
/**
@@ -410,7 +419,8 @@ xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
- if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC))
+ if ((ctxt != NULL) && (ctxt->sax != NULL) &&
+ (ctxt->sax->initialized == XML_SAX2_MAGIC))
schannel = ctxt->sax->serror;
__xmlRaiseError(schannel,
(ctxt->sax) ? ctxt->sax->warning : NULL,
@@ -439,16 +449,20 @@ xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error,
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
- ctxt->errNo = error;
- if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC))
- schannel = ctxt->sax->serror;
+ if (ctxt != NULL) {
+ ctxt->errNo = error;
+ if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC))
+ schannel = ctxt->sax->serror;
+ }
__xmlRaiseError(schannel,
ctxt->vctxt.error, ctxt->vctxt.userData,
ctxt, NULL, XML_FROM_DTD, error,
XML_ERR_ERROR, NULL, 0, (const char *) str1,
NULL, NULL, 0, 0,
msg, (const char *) str1);
- ctxt->valid = 0;
+ if (ctxt != NULL) {
+ ctxt->valid = 0;
+ }
}
/**
@@ -467,13 +481,16 @@ xmlFatalErrMsgInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
- ctxt->errNo = error;
+ if (ctxt != NULL)
+ ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, NULL,
ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
- ctxt->wellFormed = 0;
- if (ctxt->recovery == 0)
- ctxt->disableSAX = 1;
+ if (ctxt != NULL) {
+ ctxt->wellFormed = 0;
+ if (ctxt->recovery == 0)
+ ctxt->disableSAX = 1;
+ }
}
/**
@@ -495,14 +512,17 @@ xmlFatalErrMsgStrIntStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
- ctxt->errNo = error;
+ if (ctxt != NULL)
+ ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, NULL,
ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
NULL, 0, (const char *) str1, (const char *) str2,
NULL, val, 0, msg, str1, val, str2);
- ctxt->wellFormed = 0;
- if (ctxt->recovery == 0)
- ctxt->disableSAX = 1;
+ if (ctxt != NULL) {
+ ctxt->wellFormed = 0;
+ if (ctxt->recovery == 0)
+ ctxt->disableSAX = 1;
+ }
}
/**
@@ -521,14 +541,17 @@ xmlFatalErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
- ctxt->errNo = error;
+ if (ctxt != NULL)
+ ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL,
XML_FROM_PARSER, error, XML_ERR_FATAL,
NULL, 0, (const char *) val, NULL, NULL, 0, 0, msg,
val);
- ctxt->wellFormed = 0;
- if (ctxt->recovery == 0)
- ctxt->disableSAX = 1;
+ if (ctxt != NULL) {
+ ctxt->wellFormed = 0;
+ if (ctxt->recovery == 0)
+ ctxt->disableSAX = 1;
+ }
}
/**
@@ -547,7 +570,8 @@ xmlErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
- ctxt->errNo = error;
+ if (ctxt != NULL)
+ ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL,
XML_FROM_PARSER, error, XML_ERR_ERROR,
NULL, 0, (const char *) val, NULL, NULL, 0, 0, msg,
@@ -573,12 +597,14 @@ xmlNsErr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
- ctxt->errNo = error;
+ if (ctxt != NULL)
+ ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error,
XML_ERR_ERROR, NULL, 0, (const char *) info1,
(const char *) info2, (const char *) info3, 0, 0, msg,
info1, info2, info3);
- ctxt->nsWellFormed = 0;
+ if (ctxt != NULL)
+ ctxt->nsWellFormed = 0;
}
/************************************************************************
@@ -4862,16 +4888,12 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
if (!IS_BLANK_CH(CUR)) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after the attribute name\n");
- if (defaultValue != NULL)
- xmlFree(defaultValue);
break;
}
SKIP_BLANKS;
type = xmlParseAttributeType(ctxt, &tree);
if (type <= 0) {
- if (defaultValue != NULL)
- xmlFree(defaultValue);
break;
}
@@ -4879,8 +4901,6 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
if (!IS_BLANK_CH(CUR)) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after the attribute type\n");
- if (defaultValue != NULL)
- xmlFree(defaultValue);
if (tree != NULL)
xmlFreeEnumeration(tree);
break;
@@ -5281,7 +5301,7 @@ xmlParseElementChildrenContentDecl (xmlParserCtxtPtr ctxt, int inputchk) {
* Some normalization:
* (a | b* | c?)* == (a | b | c)*
*/
- while (cur->type == XML_ELEMENT_CONTENT_OR) {
+ while ((cur != NULL) && (cur->type == XML_ELEMENT_CONTENT_OR)) {
if ((cur->c1 != NULL) &&
((cur->c1->ocur == XML_ELEMENT_CONTENT_OPT) ||
(cur->c1->ocur == XML_ELEMENT_CONTENT_MULT)))
@@ -5308,7 +5328,7 @@ xmlParseElementChildrenContentDecl (xmlParserCtxtPtr ctxt, int inputchk) {
* (a | b*)+ == (a | b)*
* (a | b?)+ == (a | b)*
*/
- while (cur->type == XML_ELEMENT_CONTENT_OR) {
+ while ((cur != NULL) && (cur->type == XML_ELEMENT_CONTENT_OR)) {
if ((cur->c1 != NULL) &&
((cur->c1->ocur == XML_ELEMENT_CONTENT_OPT) ||
(cur->c1->ocur == XML_ELEMENT_CONTENT_MULT))) {
@@ -6105,6 +6125,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
* node cases in the reader tests
*/
if ((ctxt->parseMode == XML_PARSE_READER) &&
+ (nw != NULL) &&
(nw->type == XML_ELEMENT_NODE) &&
(nw->children == NULL))
nw->extra = 1;
@@ -11202,7 +11223,7 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
*list = NULL;
if ((URL == NULL) && (ID == NULL))
return(XML_ERR_INTERNAL_ERROR);
- if (doc == NULL) /* @@ relax but check for dereferences */
+ if (doc == NULL)
return(XML_ERR_INTERNAL_ERROR);
@@ -11243,13 +11264,9 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
xmlFreeParserCtxt(ctxt);
return(XML_ERR_INTERNAL_ERROR);
}
- if (doc != NULL) {
- newDoc->intSubset = doc->intSubset;
- newDoc->extSubset = doc->extSubset;
- newDoc->dict = doc->dict;
- } else if (oldctxt != NULL) {
- newDoc->dict = oldctxt->dict;
- }
+ newDoc->intSubset = doc->intSubset;
+ newDoc->extSubset = doc->extSubset;
+ newDoc->dict = doc->dict;
xmlDictReference(newDoc->dict);
if (doc->URL != NULL) {
@@ -11270,12 +11287,8 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
}
xmlAddChild((xmlNodePtr) newDoc, newRoot);
nodePush(ctxt, newDoc->children);
- if (doc == NULL) {
- ctxt->myDoc = newDoc;
- } else {
- ctxt->myDoc = doc;
- newRoot->doc = doc;
- }
+ ctxt->myDoc = doc;
+ newRoot->doc = doc;
/*
* Get the 4 first bytes and decode the charset
diff --git a/parserInternals.c b/parserInternals.c
index 9e9e03fd..57062991 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -941,7 +941,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
case XML_CHAR_ENCODING_ERROR:
__xmlErrEncoding(ctxt, XML_ERR_UNKNOWN_ENCODING,
"encoding unknown\n", NULL, NULL);
- break;
+ return(-1);
case XML_CHAR_ENCODING_NONE:
/* let's assume it's UTF-8 without the XML decl */
ctxt->charset = XML_CHAR_ENCODING_UTF8;
@@ -972,7 +972,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
*has also been converted into
*an UTF-8 BOM. Let's skip that BOM.
*/
- if ((ctxt->input != NULL) &&
+ if ((ctxt->input != NULL) && (ctxt->input->cur != NULL) &&
(ctxt->input->cur[0] == 0xEF) &&
(ctxt->input->cur[1] == 0xBB) &&
(ctxt->input->cur[2] == 0xBF)) {
@@ -988,15 +988,6 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
* Default handlers.
*/
switch (enc) {
- case XML_CHAR_ENCODING_ERROR:
- __xmlErrEncoding(ctxt, XML_ERR_UNKNOWN_ENCODING,
- "encoding unknown\n", NULL, NULL);
- break;
- case XML_CHAR_ENCODING_NONE:
- /* let's assume it's UTF-8 without the XML decl */
- ctxt->charset = XML_CHAR_ENCODING_UTF8;
- return(0);
- case XML_CHAR_ENCODING_UTF8:
case XML_CHAR_ENCODING_ASCII:
/* default encoding, no conversion should be needed */
ctxt->charset = XML_CHAR_ENCODING_UTF8;
@@ -1052,6 +1043,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
*/
if ((ctxt->inputNr == 1) &&
(ctxt->encoding == NULL) &&
+ (ctxt->input != NULL) &&
(ctxt->input->encoding != NULL)) {
ctxt->encoding = xmlStrdup(ctxt->input->encoding);
}
@@ -1072,6 +1064,8 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
"encoding not supported %s\n",
BAD_CAST "EUC-JP", NULL);
break;
+ default:
+ break;
}
}
if (handler == NULL)
@@ -1466,11 +1460,9 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) {
}
inputStream = xmlNewInputStream(ctxt);
- if (inputStream == NULL) {
- if (directory != NULL) xmlFree((char *) directory);
- if (URI != NULL) xmlFree((char *) URI);
+ if (inputStream == NULL)
return(NULL);
- }
+
inputStream->buf = buf;
inputStream = xmlCheckHTTPInput(ctxt, inputStream);
if (inputStream == NULL)
@@ -1922,8 +1914,10 @@ xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt,
/* Find pos and check to see if node is already in the sequence */
pos = xmlParserFindNodeInfoIndex(&ctxt->node_seq, (xmlNodePtr)
info->node);
- if (pos < ctxt->node_seq.length
- && ctxt->node_seq.buffer[pos].node == info->node) {
+
+ if ((pos < ctxt->node_seq.length) &&
+ (ctxt->node_seq.buffer != NULL) &&
+ (ctxt->node_seq.buffer[pos].node == info->node)) {
ctxt->node_seq.buffer[pos] = *info;
}
diff --git a/pattern.c b/pattern.c
index 7b3e5082..75935f0f 100644
--- a/pattern.c
+++ b/pattern.c
@@ -624,8 +624,6 @@ restart:
goto rollback;
node = node->parent;
while (node != NULL) {
- if (node == NULL)
- goto rollback;
if ((node->type == XML_ELEMENT_NODE) &&
(step->value[0] == node->name[0]) &&
(xmlStrEqual(step->value, node->name))) {
@@ -1183,10 +1181,6 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) {
NEXT;
PUSH(XML_OP_ALL, token, NULL);
} else {
- if (name == NULL) {
- ctxt->error = 1;
- goto error;
- }
PUSH(XML_OP_ELEM, name, NULL);
}
return;
diff --git a/uri.c b/uri.c
index 4ac8b200..7d60ffea 100644
--- a/uri.c
+++ b/uri.c
@@ -1078,11 +1078,13 @@ xmlURIEscape(const xmlChar * str)
static int
xmlParseURIFragment(xmlURIPtr uri, const char **str)
{
- const char *cur = *str;
-
+ const char *cur;
+
if (str == NULL)
return (-1);
+ cur = *str;
+
while (IS_URIC(cur) || IS_UNWISE(cur))
NEXT(cur);
if (uri != NULL) {
@@ -1111,11 +1113,13 @@ xmlParseURIFragment(xmlURIPtr uri, const char **str)
static int
xmlParseURIQuery(xmlURIPtr uri, const char **str)
{
- const char *cur = *str;
+ const char *cur;
if (str == NULL)
return (-1);
+ cur = *str;
+
while ((IS_URIC(cur)) ||
((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur))))
NEXT(cur);