mirror of https://github.com/AxioDL/tinyxml2.git
Merge pull request #241 from Dmitry-Me/validatePoolBlockSizeBeforeAllocation
Validate pool block has the right size before calling placement new
This commit is contained in:
commit
b38d29a8c5
13
tinyxml2.cpp
13
tinyxml2.cpp
|
@ -534,16 +534,19 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
|
||||||
#endif
|
#endif
|
||||||
XMLNode* returnNode = 0;
|
XMLNode* returnNode = 0;
|
||||||
if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
|
if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
|
||||||
|
TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() );
|
||||||
returnNode = new (_commentPool.Alloc()) XMLDeclaration( this );
|
returnNode = new (_commentPool.Alloc()) XMLDeclaration( this );
|
||||||
returnNode->_memPool = &_commentPool;
|
returnNode->_memPool = &_commentPool;
|
||||||
p += xmlHeaderLen;
|
p += xmlHeaderLen;
|
||||||
}
|
}
|
||||||
else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) {
|
else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) {
|
||||||
|
TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() );
|
||||||
returnNode = new (_commentPool.Alloc()) XMLComment( this );
|
returnNode = new (_commentPool.Alloc()) XMLComment( this );
|
||||||
returnNode->_memPool = &_commentPool;
|
returnNode->_memPool = &_commentPool;
|
||||||
p += commentHeaderLen;
|
p += commentHeaderLen;
|
||||||
}
|
}
|
||||||
else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) {
|
else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) {
|
||||||
|
TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
|
||||||
XMLText* text = new (_textPool.Alloc()) XMLText( this );
|
XMLText* text = new (_textPool.Alloc()) XMLText( this );
|
||||||
returnNode = text;
|
returnNode = text;
|
||||||
returnNode->_memPool = &_textPool;
|
returnNode->_memPool = &_textPool;
|
||||||
|
@ -551,16 +554,19 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
|
||||||
text->SetCData( true );
|
text->SetCData( true );
|
||||||
}
|
}
|
||||||
else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) {
|
else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) {
|
||||||
|
TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() );
|
||||||
returnNode = new (_commentPool.Alloc()) XMLUnknown( this );
|
returnNode = new (_commentPool.Alloc()) XMLUnknown( this );
|
||||||
returnNode->_memPool = &_commentPool;
|
returnNode->_memPool = &_commentPool;
|
||||||
p += dtdHeaderLen;
|
p += dtdHeaderLen;
|
||||||
}
|
}
|
||||||
else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
|
else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
|
||||||
|
TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );
|
||||||
returnNode = new (_elementPool.Alloc()) XMLElement( this );
|
returnNode = new (_elementPool.Alloc()) XMLElement( this );
|
||||||
returnNode->_memPool = &_elementPool;
|
returnNode->_memPool = &_elementPool;
|
||||||
p += elementHeaderLen;
|
p += elementHeaderLen;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
|
||||||
returnNode = new (_textPool.Alloc()) XMLText( this );
|
returnNode = new (_textPool.Alloc()) XMLText( this );
|
||||||
returnNode->_memPool = &_textPool;
|
returnNode->_memPool = &_textPool;
|
||||||
p = start; // Back it up, all the text counts.
|
p = start; // Back it up, all the text counts.
|
||||||
|
@ -1423,6 +1429,7 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !attrib ) {
|
if ( !attrib ) {
|
||||||
|
TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );
|
||||||
attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
|
attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
|
||||||
attrib->_memPool = &_document->_attributePool;
|
attrib->_memPool = &_document->_attributePool;
|
||||||
if ( last ) {
|
if ( last ) {
|
||||||
|
@ -1472,6 +1479,7 @@ char* XMLElement::ParseAttributes( char* p )
|
||||||
|
|
||||||
// attribute.
|
// attribute.
|
||||||
if (XMLUtil::IsNameStartChar( *p ) ) {
|
if (XMLUtil::IsNameStartChar( *p ) ) {
|
||||||
|
TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );
|
||||||
XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
|
XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
|
||||||
attrib->_memPool = &_document->_attributePool;
|
attrib->_memPool = &_document->_attributePool;
|
||||||
attrib->_memPool->SetTracked();
|
attrib->_memPool->SetTracked();
|
||||||
|
@ -1693,6 +1701,7 @@ void XMLDocument::Clear()
|
||||||
|
|
||||||
XMLElement* XMLDocument::NewElement( const char* name )
|
XMLElement* XMLDocument::NewElement( const char* name )
|
||||||
{
|
{
|
||||||
|
TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );
|
||||||
XMLElement* ele = new (_elementPool.Alloc()) XMLElement( this );
|
XMLElement* ele = new (_elementPool.Alloc()) XMLElement( this );
|
||||||
ele->_memPool = &_elementPool;
|
ele->_memPool = &_elementPool;
|
||||||
ele->SetName( name );
|
ele->SetName( name );
|
||||||
|
@ -1702,6 +1711,7 @@ XMLElement* XMLDocument::NewElement( const char* name )
|
||||||
|
|
||||||
XMLComment* XMLDocument::NewComment( const char* str )
|
XMLComment* XMLDocument::NewComment( const char* str )
|
||||||
{
|
{
|
||||||
|
TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() );
|
||||||
XMLComment* comment = new (_commentPool.Alloc()) XMLComment( this );
|
XMLComment* comment = new (_commentPool.Alloc()) XMLComment( this );
|
||||||
comment->_memPool = &_commentPool;
|
comment->_memPool = &_commentPool;
|
||||||
comment->SetValue( str );
|
comment->SetValue( str );
|
||||||
|
@ -1711,6 +1721,7 @@ XMLComment* XMLDocument::NewComment( const char* str )
|
||||||
|
|
||||||
XMLText* XMLDocument::NewText( const char* str )
|
XMLText* XMLDocument::NewText( const char* str )
|
||||||
{
|
{
|
||||||
|
TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
|
||||||
XMLText* text = new (_textPool.Alloc()) XMLText( this );
|
XMLText* text = new (_textPool.Alloc()) XMLText( this );
|
||||||
text->_memPool = &_textPool;
|
text->_memPool = &_textPool;
|
||||||
text->SetValue( str );
|
text->SetValue( str );
|
||||||
|
@ -1720,6 +1731,7 @@ XMLText* XMLDocument::NewText( const char* str )
|
||||||
|
|
||||||
XMLDeclaration* XMLDocument::NewDeclaration( const char* str )
|
XMLDeclaration* XMLDocument::NewDeclaration( const char* str )
|
||||||
{
|
{
|
||||||
|
TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() );
|
||||||
XMLDeclaration* dec = new (_commentPool.Alloc()) XMLDeclaration( this );
|
XMLDeclaration* dec = new (_commentPool.Alloc()) XMLDeclaration( this );
|
||||||
dec->_memPool = &_commentPool;
|
dec->_memPool = &_commentPool;
|
||||||
dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" );
|
dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" );
|
||||||
|
@ -1729,6 +1741,7 @@ XMLDeclaration* XMLDocument::NewDeclaration( const char* str )
|
||||||
|
|
||||||
XMLUnknown* XMLDocument::NewUnknown( const char* str )
|
XMLUnknown* XMLDocument::NewUnknown( const char* str )
|
||||||
{
|
{
|
||||||
|
TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() );
|
||||||
XMLUnknown* unk = new (_commentPool.Alloc()) XMLUnknown( this );
|
XMLUnknown* unk = new (_commentPool.Alloc()) XMLUnknown( this );
|
||||||
unk->_memPool = &_commentPool;
|
unk->_memPool = &_commentPool;
|
||||||
unk->SetValue( str );
|
unk->SetValue( str );
|
||||||
|
|
Loading…
Reference in New Issue