diff options
author | Mike Hommey <mh@glandium.org> | 2004-09-10 05:26:00 +0000 |
---|---|---|
committer | Mike Hommey <mh@glandium.org> | 2004-09-10 05:26:00 +0000 |
commit | 09deb06614c3408ec0816a3c88920138bae2083c (patch) | |
tree | a1b841a7dc28eecb98ca361c9371ecd1449a1908 /tree.c | |
parent | c14c53a3645d81281058d4bb4cff24fa8d6faf33 (diff) | |
download | libxml2-09deb06614c3408ec0816a3c88920138bae2083c.tar.gz |
Load /tmp/tmp.BmUFjT/libxml2-2.6.13 intoupstream/2.6.13
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'tree.c')
-rw-r--r-- | tree.c | 139 |
1 files changed, 98 insertions, 41 deletions
@@ -73,16 +73,16 @@ xmlTreeErr(int code, xmlNodePtr node, const char *extra) switch(code) { case XML_TREE_INVALID_HEX: - msg = "invalid hexadecimal character value"; + msg = "invalid hexadecimal character value\n"; break; case XML_TREE_INVALID_DEC: - msg = "invalid decimal character value"; + msg = "invalid decimal character value\n"; break; case XML_TREE_UNTERMINATED_ENTITY: - msg = "unterminated entity reference %15s"; + msg = "unterminated entity reference %15s\n"; break; default: - msg = "unexpected error number"; + msg = "unexpected error number\n"; } __xmlSimpleError(XML_FROM_TREE, code, node, msg, extra); } @@ -912,12 +912,36 @@ xmlCreateIntSubset(xmlDocPtr doc, const xmlChar *name, memset(cur, 0, sizeof(xmlDtd)); cur->type = XML_DTD_NODE; - if (name != NULL) - cur->name = xmlStrdup(name); - if (ExternalID != NULL) + if (name != NULL) { + cur->name = xmlStrdup(name); + if (cur->name == NULL) { + xmlTreeErrMemory("building internal subset"); + xmlFree(cur); + return(NULL); + } + } + if (ExternalID != NULL) { cur->ExternalID = xmlStrdup(ExternalID); - if (SystemID != NULL) + if (cur->ExternalID == NULL) { + xmlTreeErrMemory("building internal subset"); + if (cur->name != NULL) + xmlFree((char *)cur->name); + xmlFree(cur); + return(NULL); + } + } + if (SystemID != NULL) { cur->SystemID = xmlStrdup(SystemID); + if (cur->SystemID == NULL) { + xmlTreeErrMemory("building internal subset"); + if (cur->name != NULL) + xmlFree((char *)cur->name); + if (cur->ExternalID != NULL) + xmlFree((char *)cur->ExternalID); + xmlFree(cur); + return(NULL); + } + } if (doc != NULL) { doc->intSubset = cur; cur->parent = doc; @@ -996,12 +1020,15 @@ xmlFreeDtd(xmlDtdPtr cur) { xmlNodePtr next, c = cur->children; /* - * Cleanup all the DTD comments they are not in the DTD - * indexes. + * Cleanup all nodes which are not part of the specific lists + * of notations, elements, attributes and entities. */ while (c != NULL) { next = c->next; - if ((c->type == XML_COMMENT_NODE) || (c->type == XML_PI_NODE)) { + if ((c->type != XML_NOTATION_NODE) && + (c->type != XML_ELEMENT_DECL) && + (c->type != XML_ATTRIBUTE_DECL) && + (c->type != XML_ENTITY_DECL)) { xmlUnlinkNode(c); xmlFreeNode(c); } @@ -1054,6 +1081,11 @@ xmlNewDoc(const xmlChar *version) { cur->type = XML_DOCUMENT_NODE; cur->version = xmlStrdup(version); + if (cur->version == NULL) { + xmlTreeErrMemory("building doc"); + xmlFree(cur); + return(NULL); + } cur->standalone = -1; cur->compression = -1; /* not initialized */ cur->doc = cur; @@ -1861,7 +1893,6 @@ xmlNewNsPropEatName(xmlNodePtr node, xmlNsPtr ns, xmlChar *name, cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); if (cur == NULL) { xmlTreeErrMemory("building attribute"); - xmlFree(name); return(NULL); } memset(cur, 0, sizeof(xmlAttr)); @@ -2172,7 +2203,6 @@ xmlNewNodeEatName(xmlNsPtr ns, xmlChar *name) { cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); if (cur == NULL) { xmlTreeErrMemory("building node"); - xmlFree(name); return(NULL); } memset(cur, 0, sizeof(xmlNode)); @@ -3847,7 +3877,8 @@ xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, out: /* if parent != NULL we already registered the node above */ - if (parent == NULL && xmlRegisterNodeDefaultValue) + if ((parent == NULL) && + ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))) xmlRegisterNodeDefaultValue((xmlNodePtr)ret); return(ret); } @@ -4253,8 +4284,8 @@ xmlGetNodePath(xmlNodePtr node) if (occur == 0) { tmp = cur->next; while (tmp != NULL && occur == 0) { - if ((cur->type == XML_TEXT_NODE) || - (cur->type == XML_CDATA_SECTION_NODE)) + if ((tmp->type == XML_TEXT_NODE) || + (tmp->type == XML_CDATA_SECTION_NODE)) occur++; tmp = tmp->next; } @@ -5783,7 +5814,7 @@ xmlReconciliateNs(xmlDocPtr doc, xmlNodePtr tree) { /* * Browse the full subtree, deep first */ - if (node->children != NULL) { + if (node->children != NULL && node->type != XML_ENTITY_REF_NODE) { /* deep first */ node = node->children; } else if ((node != tree) && (node->next != NULL)) { @@ -6607,7 +6638,18 @@ xmlBufferGrow(xmlBufferPtr buf, unsigned int len) { if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); if (len + buf->use < buf->size) return(0); +/* + * Windows has a BIG problem on realloc timing, so we try to double + * the buffer size (if that's enough) (bug 146697) + */ +#ifdef WIN32 + if (buf->size > len) + size = buf->size * 2; + else + size = buf->use + len + 100; +#else size = buf->use + len + 100; +#endif newbuf = (xmlChar *) xmlRealloc(buf->content, size); if (newbuf == NULL) { @@ -6738,8 +6780,8 @@ xmlBufferResize(xmlBufferPtr buf, unsigned int size) if (rebuf != NULL) { memcpy(rebuf, buf->content, buf->use); xmlFree(buf->content); + rebuf[buf->use] = 0; } - rebuf[buf->use] = 0; } if (rebuf == NULL) { xmlTreeErrMemory("growing buffer"); @@ -6759,8 +6801,11 @@ xmlBufferResize(xmlBufferPtr buf, unsigned int size) * * Add a string range to an XML buffer. if len == -1, the length of * str is recomputed. + * + * Returns 0 successful, a positive error code number otherwise + * and -1 in case of internal or API error. */ -void +int xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len) { unsigned int needSize; @@ -6769,34 +6814,35 @@ xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len) { xmlGenericError(xmlGenericErrorContext, "xmlBufferAdd: str == NULL\n"); #endif - return; + return -1; } - if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return; + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; if (len < -1) { #ifdef DEBUG_BUFFER xmlGenericError(xmlGenericErrorContext, "xmlBufferAdd: len < 0\n"); #endif - return; + return -1; } - if (len == 0) return; + if (len == 0) return 0; if (len < 0) len = xmlStrlen(str); - if (len <= 0) return; + if (len <= 0) return -1; needSize = buf->use + len + 2; if (needSize > buf->size){ if (!xmlBufferResize(buf, needSize)){ xmlTreeErrMemory("growing buffer"); - return; + return XML_ERR_NO_MEMORY; } } memmove(&buf->content[buf->use], str, len*sizeof(xmlChar)); buf->use += len; buf->content[buf->use] = 0; + return 0; } /** @@ -6807,38 +6853,41 @@ xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len) { * * Add a string range to the beginning of an XML buffer. * if len == -1, the length of @str is recomputed. + * + * Returns 0 successful, a positive error code number otherwise + * and -1 in case of internal or API error. */ -void +int xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, int len) { unsigned int needSize; - if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return; + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; if (str == NULL) { #ifdef DEBUG_BUFFER xmlGenericError(xmlGenericErrorContext, "xmlBufferAddHead: str == NULL\n"); #endif - return; + return -1; } if (len < -1) { #ifdef DEBUG_BUFFER xmlGenericError(xmlGenericErrorContext, "xmlBufferAddHead: len < 0\n"); #endif - return; + return -1; } - if (len == 0) return; + if (len == 0) return 0; if (len < 0) len = xmlStrlen(str); - if (len <= 0) return; + if (len <= 0) return -1; needSize = buf->use + len + 2; if (needSize > buf->size){ if (!xmlBufferResize(buf, needSize)){ xmlTreeErrMemory("growing buffer"); - return; + return XML_ERR_NO_MEMORY; } } @@ -6846,20 +6895,24 @@ xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, int len) { memmove(&buf->content[0], str, len * sizeof(xmlChar)); buf->use += len; buf->content[buf->use] = 0; + return 0; } /** * xmlBufferCat: - * @buf: the buffer to dump + * @buf: the buffer to add to * @str: the #xmlChar string * * Append a zero terminated string to an XML buffer. + * + * Returns 0 successful, a positive error code number otherwise + * and -1 in case of internal or API error. */ -void +int xmlBufferCat(xmlBufferPtr buf, const xmlChar *str) { - if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return; - if (str != NULL) - xmlBufferAdd(buf, str, -1); + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; + if (str == NULL) return -1; + return xmlBufferAdd(buf, str, -1); } /** @@ -6868,29 +6921,33 @@ xmlBufferCat(xmlBufferPtr buf, const xmlChar *str) { * @str: the C char string * * Append a zero terminated C string to an XML buffer. + * + * Returns 0 successful, a positive error code number otherwise + * and -1 in case of internal or API error. */ -void +int xmlBufferCCat(xmlBufferPtr buf, const char *str) { const char *cur; - if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return; + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; if (str == NULL) { #ifdef DEBUG_BUFFER xmlGenericError(xmlGenericErrorContext, "xmlBufferCCat: str == NULL\n"); #endif - return; + return -1; } for (cur = str;*cur != 0;cur++) { if (buf->use + 10 >= buf->size) { if (!xmlBufferResize(buf, buf->use+10)){ xmlTreeErrMemory("growing buffer"); - return; + return XML_ERR_NO_MEMORY; } } buf->content[buf->use++] = *cur; } buf->content[buf->use] = 0; + return 0; } /** |