summaryrefslogtreecommitdiff
path: root/SAX2.c
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2004-09-10 05:26:00 +0000
committerMike Hommey <mh@glandium.org>2004-09-10 05:26:00 +0000
commit09deb06614c3408ec0816a3c88920138bae2083c (patch)
treea1b841a7dc28eecb98ca361c9371ecd1449a1908 /SAX2.c
parentc14c53a3645d81281058d4bb4cff24fa8d6faf33 (diff)
downloadlibxml2-09deb06614c3408ec0816a3c88920138bae2083c.tar.gz
Load /tmp/tmp.BmUFjT/libxml2-2.6.13 intoupstream/2.6.13
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'SAX2.c')
-rw-r--r--SAX2.c130
1 files changed, 53 insertions, 77 deletions
diff --git a/SAX2.c b/SAX2.c
index cc65e0a..fc0a8bf 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -44,6 +44,20 @@
"Unimplemented block at %s:%d\n", \
__FILE__, __LINE__);
+/*
+ * xmlSAX2ErrMemory:
+ * @ctxt: an XML validation parser context
+ * @msg: a string to accompany the error message
+ */
+static void
+xmlSAX2ErrMemory(xmlParserCtxtPtr ctxt, const char *msg) {
+ if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+ ctxt->sax->error(ctxt->userData, "%s: out of memory\n", msg);
+ ctxt->errNo = XML_ERR_NO_MEMORY;
+ ctxt->instate = XML_PARSER_EOF;
+ ctxt->disableSAX = 1;
+}
+
/**
* xmlValidError:
* @ctxt: an XML validation parser context
@@ -214,6 +228,8 @@ xmlSAX2InternalSubset(void *ctx, const xmlChar *name,
}
ctxt->myDoc->intSubset =
xmlCreateIntSubset(ctxt->myDoc, name, ExternalID, SystemID);
+ if (ctxt->myDoc->intSubset == NULL)
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2InternalSubset");
}
/**
@@ -273,13 +289,7 @@ xmlSAX2ExternalSubset(void *ctx, const xmlChar *name,
ctxt->inputTab = (xmlParserInputPtr *)
xmlMalloc(5 * sizeof(xmlParserInputPtr));
if (ctxt->inputTab == NULL) {
- ctxt->errNo = XML_ERR_NO_MEMORY;
- if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
- ctxt->sax->error(ctxt->userData,
- "xmlSAX2ExternalSubset: out of memory\n");
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2ExternalSubset");
ctxt->input = oldinput;
ctxt->inputNr = oldinputNr;
ctxt->inputMax = oldinputMax;
@@ -816,12 +826,7 @@ xmlSAX2StartDocument(void *ctx)
if (ctxt->myDoc == NULL)
ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
if (ctxt->myDoc == NULL) {
- if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
- ctxt->sax->error(ctxt->userData,
- "SAX.xmlSAX2StartDocument(): out of memory\n");
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument");
return;
}
#else
@@ -841,12 +846,7 @@ xmlSAX2StartDocument(void *ctx)
doc->encoding = NULL;
doc->standalone = ctxt->standalone;
} else {
- if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
- ctxt->sax->error(ctxt->userData,
- "SAX.xmlSAX2StartDocument(): out of memory\n");
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument");
return;
}
if ((ctxt->dictNames) && (doc != NULL)) {
@@ -858,7 +858,7 @@ xmlSAX2StartDocument(void *ctx)
(ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
ctxt->myDoc->URL = xmlCanonicPath((const xmlChar *) ctxt->input->filename);
if (ctxt->myDoc->URL == NULL)
- ctxt->myDoc->URL = xmlStrdup((const xmlChar *) ctxt->input->filename);
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument");
}
}
@@ -945,12 +945,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
name = xmlStrdup(fullname);
}
if (name == NULL) {
- if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
- ctxt->sax->error(ctxt->userData,
- "SAX.xmlSAX2StartElement(): out of memory\n");
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
if (ns != NULL)
xmlFree(ns);
return;
@@ -1044,12 +1039,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
0,0,0);
ctxt->depth--;
if (val == NULL) {
- if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
- ctxt->sax->error(ctxt->userData,
- "SAX.xmlSAX2StartElement(): out of memory\n");
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
xmlFree(ns);
if (name != NULL)
xmlFree(name);
@@ -1345,13 +1335,7 @@ process_external_subset:
fulln = xmlBuildQName(attr->name, attr->prefix, fn, 50);
if (fulln == NULL) {
- if ((ctxt->sax != NULL) &&
- (ctxt->sax->error != NULL))
- ctxt->sax->error(ctxt->userData,
- "SAX.xmlSAX2StartElement(): out of memory\n");
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
return;
}
@@ -1446,9 +1430,7 @@ xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
if (ret == NULL) {
if (prefix != NULL)
xmlFree(prefix);
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
return;
}
if (ctxt->myDoc->children == NULL) {
@@ -1672,12 +1654,7 @@ xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) {
ret = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));
}
if (ret == NULL) {
- if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
- ctxt->sax->error(ctxt->userData,
- "SAX.xmlSAX2Characters(): out of memory\n");
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlErrMemory(ctxt, "xmlSAX2Characters");
return(NULL);
}
/*
@@ -1705,9 +1682,14 @@ skip:
ret->type = XML_TEXT_NODE;
ret->name = xmlStringText;
- if (intern == NULL)
+ if (intern == NULL) {
ret->content = xmlStrndup(str, len);
- else
+ if (ret->content == NULL) {
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2TextNode");
+ xmlFree(ret);
+ return(NULL);
+ }
+ } else
ret->content = (xmlChar *) intern;
if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
@@ -1816,9 +1798,7 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt,
else
ret = xmlNewNsProp(ctxt->node, namespace, localname, NULL);
if (ret == NULL) {
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlErrMemory(ctxt, "xmlSAX2AttributeNs");
return;
}
}
@@ -2033,9 +2013,13 @@ xmlSAX2StartElementNs(void *ctx,
if (ctxt->dictNames)
ret->name = localname;
- else
+ else {
ret->name = xmlStrdup(localname);
-
+ if (ret->name == NULL) {
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
+ return;
+ }
+ }
if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
xmlRegisterNodeDefaultValue(ret);
} else {
@@ -2045,9 +2029,7 @@ xmlSAX2StartElementNs(void *ctx,
else
ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL);
if (ret == NULL) {
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
return;
}
}
@@ -2060,10 +2042,8 @@ xmlSAX2StartElementNs(void *ctx,
}
}
- if (ctxt->myDoc->children == NULL) {
+ if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
- } else if (parent == NULL) {
- parent = ctxt->myDoc->children;
}
/*
* Build the namespace list
@@ -2082,9 +2062,7 @@ xmlSAX2StartElementNs(void *ctx,
if ((URI != NULL) && (prefix == pref))
ret->ns = ns;
} else {
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
return;
}
#ifdef LIBXML_VALID_ENABLED
@@ -2122,11 +2100,16 @@ xmlSAX2StartElementNs(void *ctx,
/*
* Search the namespace if it wasn't already found
+ * Note that, if prefix is NULL, this searches for the default Ns
*/
if ((URI != NULL) && (ret->ns == NULL)) {
- ret->ns = xmlSearchNs(ctxt->myDoc, parent, prefix);
+ ret->ns = xmlSearchNs(ctxt->myDoc, parent, prefix);
if (ret->ns == NULL) {
ns = xmlNewNs(ret, NULL, prefix);
+ if (ns == NULL) {
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
+ return;
+ }
if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt->userData,
"Namespace prefix %s was not found\n", prefix);
@@ -2281,6 +2264,9 @@ xmlSAX2Characters(void *ctx, const xmlChar *ch, int len)
lastChild->doc = ctxt->node->doc;
ctxt->nodelen = len;
ctxt->nodemem = len + 1;
+ } else {
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters");
+ return;
}
} else {
int coalesceText = (lastChild != NULL) &&
@@ -2306,12 +2292,7 @@ xmlSAX2Characters(void *ctx, const xmlChar *ch, int len)
size *= 2;
newbuf = (xmlChar *) xmlRealloc(lastChild->content,size);
if (newbuf == NULL) {
- if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
- ctxt->sax->error(ctxt->userData,
- "SAX.xmlSAX2Characters(): out of memory\n");
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters");
return;
}
ctxt->nodemem = size;
@@ -2322,12 +2303,7 @@ xmlSAX2Characters(void *ctx, const xmlChar *ch, int len)
lastChild->content[ctxt->nodelen] = 0;
} else if (coalesceText) {
if (xmlTextConcat(lastChild, ch, len)) {
- if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
- ctxt->sax->error(ctxt->userData,
- "SAX.xmlSAX2Characters(): out of memory\n");
- ctxt->errNo = XML_ERR_NO_MEMORY;
- ctxt->instate = XML_PARSER_EOF;
- ctxt->disableSAX = 1;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters");
}
if (ctxt->node->children != NULL) {
ctxt->nodelen = xmlStrlen(lastChild->content);