To fix "infinite loop bug when parsing XML with text
inlined in same level as nodes" described in:
http://sourceforge.net/tracker/index.php?
func=detail&aid=1195696&group_id=13559&atid=113559
https://sourceforge.net/forum/forum.php?
thread_id=1278594&forum_id=42748
Replace version 2.3.4 implementation of
TiXmlElement::ReadValue() in tinyxmlparser.cpp to:
const char* TiXmlElement::ReadValue( const char* p,
TiXmlParsingData* data, TiXmlEncoding encoding )
{
TiXmlDocument* document = GetDocument();
while ( p && *p )
{
const char* pWithWhiteSpace = p;
// Read in text and elements in
any order.
p = SkipWhiteSpace( p,
encoding );
if ( !*p )
break;
if ( *p != '<' )
{
// Take what we have,
make a text element.
TiXmlText* textNode =
new TiXmlText( "" );
if ( !textNode )
{
if (
document ) document->SetError(
TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding );
return 0;
}
if (
TiXmlBase::IsWhiteSpaceCondensed() )
{
p =
textNode->Parse( p, data, encoding );
}
else
{
// Special
case: we want to keep the white space
// so that
leading spaces aren't removed.
p =
textNode->Parse( pWithWhiteSpace, data, encoding );
}
if ( !textNode->Blank() )
LinkEndChild( textNode );
else
delete
textNode;
}
else
{
// We hit a '<'
// Have we hit a new
element or an end tag?
if ( StringEqual( p, "</",
false, encoding ) )
{
return p;
}
else
{
TiXmlNode*
node = Identify( p, encoding );
if ( node )
{
p = node->Parse( p, data, encoding );
LinkEndChild( node );
}
else
{
return 0;
}
}
}
}
if ( !p )
{
if ( document ) document-
>SetError(
TIXML_ERROR_READING_ELEMENT_VALUE, 0, 0,
encoding );
}
return p;
}
Basically, pWithWhiteSpace is now contained inside
the loop and always updated. The SkipWhiteSpace call
at later part of the loop has been deleted so that in the
next loop iteration, leading white space will still be
included in pWithWhiteSpace.
Thanks!
--Marlon Baculio
tinyxmlparser.cpp based on 2.3.4