Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tinyxml2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2344,9 +2344,12 @@ static FILE* callfopen( const char* filepath, const char* mode )
return fp;
}

void XMLDocument::DeleteNode( XMLNode* node ) {
void XMLDocument::DeleteNode( XMLNode* node ) {
TIXMLASSERT( node );
TIXMLASSERT(node->_document == this );
if(node == 0) {
return; // check for null pointer
}
if (node->_parent) {
node->_parent->DeleteChild( node );
}
Expand Down
8 changes: 7 additions & 1 deletion xmltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down