Merge pull request #239 from Dmitry-Me/addMorePointerAsserts

More pointer pre-asserts
This commit is contained in:
Lee Thomason 2014-12-09 11:14:16 -08:00
commit f0e8fac4ee
2 changed files with 31 additions and 7 deletions

View File

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

View File

@ -1666,6 +1666,8 @@ public:
It will be unlinked from the DOM. It will be unlinked from the DOM.
*/ */
void DeleteNode( XMLNode* node ) { void DeleteNode( XMLNode* node ) {
TIXMLASSERT( node );
TIXMLASSERT( node->_parent );
node->_parent->DeleteChild( node ); node->_parent->DeleteChild( node );
} }