mirror of
https://github.com/leethomason/tinyxml2.git
synced 2026-07-23 04:03:00 +04:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ce9f9a3a7 | |||
| 682fda289f | |||
| e6a464942f | |||
| 98137e6936 | |||
| aba13c50bf | |||
| e48a1310fe | |||
| fc99428a82 |
+18
-4
@@ -114,6 +114,9 @@ distribution.
|
||||
#define TIXML_VSNPRINTF vsnprintf
|
||||
static inline int TIXML_VSCPRINTF( const char* format, va_list va )
|
||||
{
|
||||
if (!format) {
|
||||
return 0;
|
||||
}
|
||||
int len = vsnprintf( 0, 0, format, va );
|
||||
TIXMLASSERT( len >= 0 );
|
||||
return len;
|
||||
@@ -831,7 +834,17 @@ XMLNode::XMLNode( XMLDocument* doc ) :
|
||||
|
||||
XMLNode::~XMLNode()
|
||||
{
|
||||
DeleteChildren();
|
||||
// Fast path: this node is dying, so maintaining _firstChild/_lastChild and
|
||||
// sibling _prev/_next links is unnecessary. Only _parent must be zeroed to
|
||||
// satisfy the MarkInUse assertion inside DeleteNode.
|
||||
XMLNode *currentChild = _firstChild;
|
||||
while (currentChild != NULL) {
|
||||
XMLNode *next = currentChild->_next;
|
||||
currentChild->_parent = 0;
|
||||
DeleteNode(currentChild);
|
||||
currentChild = next;
|
||||
}
|
||||
|
||||
if ( _parent ) {
|
||||
_parent->Unlink( this );
|
||||
}
|
||||
@@ -2344,9 +2357,10 @@ static FILE* callfopen( const char* filepath, const char* mode )
|
||||
return fp;
|
||||
}
|
||||
|
||||
void XMLDocument::DeleteNode( XMLNode* node ) {
|
||||
TIXMLASSERT( node );
|
||||
TIXMLASSERT(node->_document == this );
|
||||
void XMLDocument::DeleteNode( XMLNode* node ) {
|
||||
if(node == 0) {
|
||||
return; // check for null pointer
|
||||
}
|
||||
if (node->_parent) {
|
||||
node->_parent->DeleteChild( node );
|
||||
}
|
||||
|
||||
+7
-1
@@ -2025,7 +2025,13 @@ int main( int argc, const char ** argv )
|
||||
XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", true, 0 == doc.RootElement()->FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
//Check the robustness of the DeleteNode function in handling null pointers.
|
||||
{
|
||||
XMLDocument doc;
|
||||
doc.DeleteNode(nullptr);
|
||||
XMLTest("DeleteNode with null pointer", true, doc.Error() == XML_SUCCESS);
|
||||
}
|
||||
|
||||
// Check sample xml can be parsed with pedantic mode
|
||||
{
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
|
||||
Reference in New Issue
Block a user