diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 1f43faa..4ce2184 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -623,6 +623,7 @@ void XMLNode::SetValue( const char* str, bool staticMem ) void XMLNode::DeleteChildren() { while( _firstChild ) { + TIXMLASSERT( _firstChild->_document == _document ); XMLNode* node = _firstChild; Unlink( node ); @@ -634,6 +635,7 @@ void XMLNode::DeleteChildren() void XMLNode::Unlink( XMLNode* child ) { + TIXMLASSERT( child->_document == _document ); if ( child == _firstChild ) { _firstChild = _firstChild->_next; } @@ -653,6 +655,7 @@ void XMLNode::Unlink( XMLNode* child ) void XMLNode::DeleteChild( XMLNode* node ) { + TIXMLASSERT( node->_document == _document ); TIXMLASSERT( node->_parent == this ); DeleteNode( node ); } @@ -660,8 +663,10 @@ void XMLNode::DeleteChild( XMLNode* node ) XMLNode* XMLNode::InsertEndChild( XMLNode* addThis ) { - if (addThis->_document != _document) - return 0; + if ( addThis->_document != _document ) { + TIXMLASSERT( false ); + return 0; + } if (addThis->_parent) addThis->_parent->Unlink( addThis ); @@ -691,8 +696,10 @@ XMLNode* XMLNode::InsertEndChild( XMLNode* addThis ) XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis ) { - if (addThis->_document != _document) - return 0; + if ( addThis->_document != _document ) { + TIXMLASSERT( false ); + return 0; + } if (addThis->_parent) addThis->_parent->Unlink( addThis ); @@ -723,12 +730,16 @@ XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis ) XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ) { - if (addThis->_document != _document) - return 0; + TIXMLASSERT( addThis ); + if ( addThis->_document != _document ) { + TIXMLASSERT( false ); + return 0; + } - TIXMLASSERT( afterThis->_parent == this ); + TIXMLASSERT( afterThis ); if ( afterThis->_parent != this ) { + TIXMLASSERT( false ); return 0; } @@ -944,6 +955,7 @@ bool XMLText::ShallowEqual( const XMLNode* compare ) const bool XMLText::Accept( XMLVisitor* visitor ) const { + TIXMLASSERT( visitor ); return visitor->Visit( *this ); } @@ -984,6 +996,7 @@ XMLNode* XMLComment::ShallowClone( XMLDocument* doc ) const bool XMLComment::ShallowEqual( const XMLNode* compare ) const { + TIXMLASSERT( compare ); const XMLComment* comment = compare->ToComment(); return ( comment && XMLUtil::StringEqual( comment->Value(), Value() )); } @@ -991,6 +1004,7 @@ bool XMLComment::ShallowEqual( const XMLNode* compare ) const bool XMLComment::Accept( XMLVisitor* visitor ) const { + TIXMLASSERT( visitor ); return visitor->Visit( *this ); } @@ -1032,6 +1046,7 @@ XMLNode* XMLDeclaration::ShallowClone( XMLDocument* doc ) const bool XMLDeclaration::ShallowEqual( const XMLNode* compare ) const { + TIXMLASSERT( compare ); const XMLDeclaration* declaration = compare->ToDeclaration(); return ( declaration && XMLUtil::StringEqual( declaration->Value(), Value() )); } @@ -1040,6 +1055,7 @@ bool XMLDeclaration::ShallowEqual( const XMLNode* compare ) const bool XMLDeclaration::Accept( XMLVisitor* visitor ) const { + TIXMLASSERT( visitor ); return visitor->Visit( *this ); } @@ -1080,6 +1096,7 @@ XMLNode* XMLUnknown::ShallowClone( XMLDocument* doc ) const bool XMLUnknown::ShallowEqual( const XMLNode* compare ) const { + TIXMLASSERT( compare ); const XMLUnknown* unknown = compare->ToUnknown(); return ( unknown && XMLUtil::StringEqual( unknown->Value(), Value() )); } @@ -1087,6 +1104,7 @@ bool XMLUnknown::ShallowEqual( const XMLNode* compare ) const bool XMLUnknown::Accept( XMLVisitor* visitor ) const { + TIXMLASSERT( visitor ); return visitor->Visit( *this ); } @@ -1556,6 +1574,7 @@ XMLNode* XMLElement::ShallowClone( XMLDocument* doc ) const bool XMLElement::ShallowEqual( const XMLNode* compare ) const { + TIXMLASSERT( compare ); const XMLElement* other = compare->ToElement(); if ( other && XMLUtil::StringEqual( other->Value(), Value() )) { @@ -1581,6 +1600,7 @@ bool XMLElement::ShallowEqual( const XMLNode* compare ) const bool XMLElement::Accept( XMLVisitor* visitor ) const { + TIXMLASSERT( visitor ); if ( visitor->VisitEnter( *this, _rootAttribute ) ) { for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) { if ( !node->Accept( visitor ) ) { @@ -1717,6 +1737,8 @@ XMLUnknown* XMLDocument::NewUnknown( const char* str ) static FILE* callfopen( const char* filepath, const char* mode ) { + TIXMLASSERT( filepath ); + TIXMLASSERT( mode ); #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE) FILE* fp = 0; errno_t err = fopen_s( &fp, filepath, mode ); diff --git a/tinyxml2.h b/tinyxml2.h index 266efc7..54190c9 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -1666,6 +1666,8 @@ public: It will be unlinked from the DOM. */ void DeleteNode( XMLNode* node ) { + TIXMLASSERT( node ); + TIXMLASSERT( node->_parent ); node->_parent->DeleteChild( node ); }