1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 20:25:14 +03:00

fixing bug #344390 with xmlReconciliateNs Daniel

* tree.c: fixing bug #344390 with xmlReconciliateNs
Daniel
This commit is contained in:
Daniel Veillard 2006-10-14 08:46:40 +00:00
parent f1a27c659e
commit b5f1197ce2
2 changed files with 62 additions and 56 deletions

View File

@ -1,3 +1,7 @@
Sat Oct 14 10:46:46 CEST 2006 Daniel Veillard <daniel@veillard.com>
* tree.c: fixing bug #344390 with xmlReconciliateNs
Sat Oct 14 00:31:49 CEST 2006 Daniel Veillard <daniel@veillard.com>
* xmllint.c: added --html --memory to test htmlReadMemory to

114
tree.c
View File

@ -5936,73 +5936,75 @@ xmlReconciliateNs(xmlDocPtr doc, xmlNodePtr tree) {
/*
* now check for namespace hold by attributes on the node.
*/
attr = node->properties;
while (attr != NULL) {
if (attr->ns != NULL) {
/*
* initialize the cache if needed
*/
if (sizeCache == 0) {
sizeCache = 10;
oldNs = (xmlNsPtr *) xmlMalloc(sizeCache *
sizeof(xmlNsPtr));
if (oldNs == NULL) {
xmlTreeErrMemory("fixing namespaces");
return(-1);
}
newNs = (xmlNsPtr *) xmlMalloc(sizeCache *
sizeof(xmlNsPtr));
if (newNs == NULL) {
xmlTreeErrMemory("fixing namespaces");
xmlFree(oldNs);
return(-1);
}
}
for (i = 0;i < nbCache;i++) {
if (oldNs[i] == attr->ns) {
attr->ns = newNs[i];
break;
}
}
if (i == nbCache) {
if (node->type == XML_ELEMENT_NODE) {
attr = node->properties;
while (attr != NULL) {
if (attr->ns != NULL) {
/*
* OK we need to recreate a new namespace definition
* initialize the cache if needed
*/
n = xmlNewReconciliedNs(doc, tree, attr->ns);
if (n != NULL) { /* :-( what if else ??? */
/*
* check if we need to grow the cache buffers.
*/
if (sizeCache <= nbCache) {
sizeCache *= 2;
oldNs = (xmlNsPtr *) xmlRealloc(oldNs, sizeCache *
sizeof(xmlNsPtr));
if (oldNs == NULL) {
xmlTreeErrMemory("fixing namespaces");
xmlFree(newNs);
return(-1);
}
newNs = (xmlNsPtr *) xmlRealloc(newNs, sizeCache *
sizeof(xmlNsPtr));
if (newNs == NULL) {
xmlTreeErrMemory("fixing namespaces");
xmlFree(oldNs);
return(-1);
}
if (sizeCache == 0) {
sizeCache = 10;
oldNs = (xmlNsPtr *) xmlMalloc(sizeCache *
sizeof(xmlNsPtr));
if (oldNs == NULL) {
xmlTreeErrMemory("fixing namespaces");
return(-1);
}
newNs = (xmlNsPtr *) xmlMalloc(sizeCache *
sizeof(xmlNsPtr));
if (newNs == NULL) {
xmlTreeErrMemory("fixing namespaces");
xmlFree(oldNs);
return(-1);
}
}
for (i = 0;i < nbCache;i++) {
if (oldNs[i] == attr->ns) {
attr->ns = newNs[i];
break;
}
}
if (i == nbCache) {
/*
* OK we need to recreate a new namespace definition
*/
n = xmlNewReconciliedNs(doc, tree, attr->ns);
if (n != NULL) { /* :-( what if else ??? */
/*
* check if we need to grow the cache buffers.
*/
if (sizeCache <= nbCache) {
sizeCache *= 2;
oldNs = (xmlNsPtr *) xmlRealloc(oldNs,
sizeCache * sizeof(xmlNsPtr));
if (oldNs == NULL) {
xmlTreeErrMemory("fixing namespaces");
xmlFree(newNs);
return(-1);
}
newNs = (xmlNsPtr *) xmlRealloc(newNs,
sizeCache * sizeof(xmlNsPtr));
if (newNs == NULL) {
xmlTreeErrMemory("fixing namespaces");
xmlFree(oldNs);
return(-1);
}
}
newNs[nbCache] = n;
oldNs[nbCache++] = attr->ns;
attr->ns = n;
}
newNs[nbCache] = n;
oldNs[nbCache++] = attr->ns;
attr->ns = n;
}
}
attr = attr->next;
}
attr = attr->next;
}
/*
* Browse the full subtree, deep first
*/
if (node->children != NULL && node->type != XML_ENTITY_REF_NODE) {
if ((node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) {
/* deep first */
node = node->children;
} else if ((node != tree) && (node->next != NULL)) {