Fixed a crash that would result from adding a text node child adjacent to another

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/nsxml_using_libxml2@34682 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Doug Simons 2012-01-31 22:15:35 +00:00
parent 3bfd09d528
commit 469c89052e
2 changed files with 15 additions and 3 deletions

View file

@ -1,3 +1,9 @@
2012-01-31 Doug Simons <doug.simons@testplant.com>
* Source/NSXMLElement.m (-insertChild:atIndex:): Deal with the
possibility that text nodes can be merged when added, to at least
avoid crashing. This leaves the original NSXMLNode with a NULL node.
2012-01-30 22:55-EST Gregory John Casamento <greg.casamento@gmail.com>
* Source/NSXMLDocument.m: Do type check to make sure that
@ -5,7 +11,7 @@
NSData also check if it's nil. In either case throw an
exception.
2012-01-05 22:20-EST Doug Simons <doug.simons@testplant.com>
2012-01-30 22:20-EST Doug Simons <doug.simons@testplant.com>
* Source/NSXMLPrivate.h
* Source/NSXMLDocument.m

View file

@ -338,6 +338,7 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
xmlNodePtr thisNode = (xmlNodePtr)[self _node];
xmlNodePtr childNode = (xmlNodePtr)[child _node];
NSUInteger childCount = [self childCount];
xmlNodePtr addedNode = NULL;
// Check to make sure this is a valid addition...
NSAssert(nil != child, NSInvalidArgumentException);
@ -359,11 +360,16 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
if(0 == childCount || index == childCount)
{
xmlAddChild(thisNode, childNode);
addedNode = xmlAddChild(thisNode, childNode);
}
else if(index < childCount)
{
xmlAddPrevSibling(curNode, childNode);
addedNode = xmlAddPrevSibling(curNode, childNode);
}
if (addedNode != childNode)
{
[child _setNode:NULL];
child = [NSXMLNode _objectForNode:addedNode];
}
[self _addSubNode:child];