summaryrefslogtreecommitdiff
path: root/tree.c
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2004-11-11 12:53:54 +0000
committerMike Hommey <mh@glandium.org>2004-11-11 12:53:54 +0000
commitf51dd67f3a3f472af0620391eb588eeca4533689 (patch)
tree9184c396c489196608427d5fa35814e86a1e479f /tree.c
parent9705f1a5e858108d21a0128556f42b25d16833cd (diff)
downloadlibxml2-f51dd67f3a3f472af0620391eb588eeca4533689.tar.gz
Load /tmp/tmp.n9GTkp/libxml2-2.6.16 intoupstream/2.6.16
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c73
1 files changed, 62 insertions, 11 deletions
diff --git a/tree.c b/tree.c
index 9de498d..134ce20 100644
--- a/tree.c
+++ b/tree.c
@@ -242,6 +242,7 @@ xmlSplitQName2(const xmlChar *name, xmlChar **prefix) {
int len = 0;
xmlChar *ret = NULL;
+ if (prefix == NULL) return(NULL);
*prefix = NULL;
if (name == NULL) return(NULL);
@@ -345,6 +346,9 @@ xmlValidateNCName(const xmlChar *value, int space) {
const xmlChar *cur = value;
int c,l;
+ if (value == NULL)
+ return(-1);
+
/*
* First quick algorithm for ASCII range
*/
@@ -416,6 +420,8 @@ xmlValidateQName(const xmlChar *value, int space) {
const xmlChar *cur = value;
int c,l;
+ if (value == NULL)
+ return(-1);
/*
* First quick algorithm for ASCII range
*/
@@ -512,6 +518,8 @@ xmlValidateName(const xmlChar *value, int space) {
const xmlChar *cur = value;
int c,l;
+ if (value == NULL)
+ return(-1);
/*
* First quick algorithm for ASCII range
*/
@@ -579,6 +587,8 @@ xmlValidateNMToken(const xmlChar *value, int space) {
const xmlChar *cur = value;
int c,l;
+ if (value == NULL)
+ return(-1);
/*
* First quick algorithm for ASCII range
*/
@@ -2145,6 +2155,7 @@ xmlNewDocPI(xmlDocPtr doc, const xmlChar *name, const xmlChar *content) {
if (content != NULL) {
cur->content = xmlStrdup(content);
}
+ cur->doc = doc;
if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
xmlRegisterNodeDefaultValue((xmlNodePtr)cur);
@@ -2503,6 +2514,9 @@ xmlNodePtr
xmlNewCharRef(xmlDocPtr doc, const xmlChar *name) {
xmlNodePtr cur;
+ if (name == NULL)
+ return(NULL);
+
/*
* Allocate a new node and fill the fields.
*/
@@ -2544,6 +2558,9 @@ xmlNewReference(xmlDocPtr doc, const xmlChar *name) {
xmlNodePtr cur;
xmlEntityPtr ent;
+ if (name == NULL)
+ return(NULL);
+
/*
* Allocate a new node and fill the fields.
*/
@@ -3510,10 +3527,11 @@ xmlUnlinkNode(xmlNodePtr cur) {
*/
xmlNodePtr
xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) {
- if (old == NULL) {
+ if (old == cur) return(NULL);
+ if ((old == NULL) || (old->parent == NULL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
- "xmlReplaceNode : old == NULL\n");
+ "xmlReplaceNode : old == NULL or without parent\n");
#endif
return(NULL);
}
@@ -4661,6 +4679,9 @@ xmlNodeGetSpacePreserve(xmlNodePtr cur) {
*/
void
xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) {
+ xmlDocPtr doc;
+ xmlDictPtr dict;
+
if (cur == NULL) return;
if (name == NULL) return;
switch(cur->type) {
@@ -4690,8 +4711,19 @@ xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) {
case XML_ENTITY_DECL:
break;
}
- if (cur->name != NULL) xmlFree((xmlChar *) cur->name);
- cur->name = xmlStrdup(name);
+ doc = cur->doc;
+ if (doc != NULL)
+ dict = doc->dict;
+ else
+ dict = NULL;
+ if (dict != NULL) {
+ if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name)))
+ xmlFree((xmlChar *) cur->name);
+ cur->name = xmlDictLookup(dict, name, -1);
+ } else {
+ if (cur->name != NULL) xmlFree((xmlChar *) cur->name);
+ cur->name = xmlStrdup(name);
+ }
}
#endif
@@ -5674,7 +5706,7 @@ xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) {
#endif
return(NULL);
}
- if (ns == NULL) {
+ if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlNewReconciliedNs : ns == NULL\n");
@@ -5742,6 +5774,9 @@ xmlReconciliateNs(xmlDocPtr doc, xmlNodePtr tree) {
xmlAttrPtr attr;
int ret = 0, i;
+ if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) return(-1);
+ if ((doc == NULL) || (doc->type != XML_DOCUMENT_NODE)) return(-1);
+ if (node->doc != doc) return(-1);
while (node != NULL) {
/*
* Reconciliate the node namespace
@@ -6294,10 +6329,11 @@ xmlUnsetProp(xmlNodePtr node, const xmlChar *name) {
*/
int
xmlUnsetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name) {
- xmlAttrPtr prop = node->properties, prev = NULL;;
+ xmlAttrPtr prop, prev = NULL;;
if ((node == NULL) || (name == NULL))
return(-1);
+ prop = node->properties;
if (ns == NULL)
return(xmlUnsetProp(node, name));
if (ns->href == NULL)
@@ -6672,6 +6708,7 @@ xmlBufferFree(xmlBufferPtr buf) {
*/
void
xmlBufferEmpty(xmlBufferPtr buf) {
+ if (buf == NULL) return;
if (buf->content == NULL) return;
buf->use = 0;
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) {
@@ -6692,6 +6729,7 @@ xmlBufferEmpty(xmlBufferPtr buf) {
*/
int
xmlBufferShrink(xmlBufferPtr buf, unsigned int len) {
+ if (buf == NULL) return(-1);
if (len == 0) return(0);
if (len > buf->use) return(-1);
@@ -6719,6 +6757,8 @@ xmlBufferGrow(xmlBufferPtr buf, unsigned int len) {
int size;
xmlChar *newbuf;
+ if (buf == NULL) return(-1);
+
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0);
if (len + buf->use < buf->size) return(0);
@@ -6828,6 +6868,9 @@ xmlBufferResize(xmlBufferPtr buf, unsigned int size)
unsigned int newSize;
xmlChar* rebuf = NULL;
+ if (buf == NULL)
+ return(0);
+
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0);
/* Don't resize if we don't have to */
@@ -6893,11 +6936,7 @@ int
xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len) {
unsigned int needSize;
- if (str == NULL) {
-#ifdef DEBUG_BUFFER
- xmlGenericError(xmlGenericErrorContext,
- "xmlBufferAdd: str == NULL\n");
-#endif
+ if ((str == NULL) || (buf == NULL)) {
return -1;
}
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1;
@@ -6945,6 +6984,8 @@ int
xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, int len) {
unsigned int needSize;
+ if (buf == NULL)
+ return(-1);
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1;
if (str == NULL) {
#ifdef DEBUG_BUFFER
@@ -6994,6 +7035,8 @@ xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, int len) {
*/
int
xmlBufferCat(xmlBufferPtr buf, const xmlChar *str) {
+ if (buf == NULL)
+ return(-1);
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1;
if (str == NULL) return -1;
return xmlBufferAdd(buf, str, -1);
@@ -7013,6 +7056,8 @@ int
xmlBufferCCat(xmlBufferPtr buf, const char *str) {
const char *cur;
+ if (buf == NULL)
+ return(-1);
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1;
if (str == NULL) {
#ifdef DEBUG_BUFFER
@@ -7044,6 +7089,8 @@ xmlBufferCCat(xmlBufferPtr buf, const char *str) {
*/
void
xmlBufferWriteCHAR(xmlBufferPtr buf, const xmlChar *string) {
+ if (buf == NULL)
+ return;
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return;
xmlBufferCat(buf, string);
}
@@ -7058,6 +7105,8 @@ xmlBufferWriteCHAR(xmlBufferPtr buf, const xmlChar *string) {
*/
void
xmlBufferWriteChar(xmlBufferPtr buf, const char *string) {
+ if (buf == NULL)
+ return;
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return;
xmlBufferCCat(buf, string);
}
@@ -7075,6 +7124,8 @@ xmlBufferWriteChar(xmlBufferPtr buf, const char *string) {
void
xmlBufferWriteQuotedString(xmlBufferPtr buf, const xmlChar *string) {
const xmlChar *cur, *base;
+ if (buf == NULL)
+ return;
if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return;
if (xmlStrchr(string, '\"')) {
if (xmlStrchr(string, '\'')) {