mirror of https://github.com/AxioDL/tinyxml2.git
fix error string memory errors
This commit is contained in:
parent
2e14517c89
commit
584af57086
24
tinyxml2.cpp
24
tinyxml2.cpp
|
@ -1829,8 +1829,6 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) :
|
|||
_processEntities( processEntities ),
|
||||
_errorID(XML_SUCCESS),
|
||||
_whitespace( whitespace ),
|
||||
_errorStr1( 0 ),
|
||||
_errorStr2( 0 ),
|
||||
_charBuffer( 0 )
|
||||
{
|
||||
// avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+)
|
||||
|
@ -1852,8 +1850,8 @@ void XMLDocument::Clear()
|
|||
const bool hadError = Error();
|
||||
#endif
|
||||
_errorID = XML_SUCCESS;
|
||||
_errorStr1 = 0;
|
||||
_errorStr2 = 0;
|
||||
_errorStr1.Reset();
|
||||
_errorStr2.Reset();
|
||||
|
||||
delete [] _charBuffer;
|
||||
_charBuffer = 0;
|
||||
|
@ -2112,8 +2110,14 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2 )
|
|||
{
|
||||
TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT );
|
||||
_errorID = error;
|
||||
_errorStr1 = str1;
|
||||
_errorStr2 = str2;
|
||||
|
||||
_errorStr1.Reset();
|
||||
_errorStr2.Reset();
|
||||
|
||||
if (str1)
|
||||
_errorStr1.SetStr(str1);
|
||||
if (str2)
|
||||
_errorStr2.SetStr(str2);
|
||||
}
|
||||
|
||||
const char* XMLDocument::ErrorName() const
|
||||
|
@ -2131,11 +2135,11 @@ void XMLDocument::PrintError() const
|
|||
char buf1[LEN] = { 0 };
|
||||
char buf2[LEN] = { 0 };
|
||||
|
||||
if ( _errorStr1 ) {
|
||||
TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr1 );
|
||||
if ( !_errorStr1.Empty() ) {
|
||||
TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr1.GetStr() );
|
||||
}
|
||||
if ( _errorStr2 ) {
|
||||
TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 );
|
||||
if ( !_errorStr2.Empty() ) {
|
||||
TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2.GetStr() );
|
||||
}
|
||||
|
||||
// Should check INT_MIN <= _errorID && _errorId <= INT_MAX, but that
|
||||
|
|
20
tinyxml2.h
20
tinyxml2.h
|
@ -127,12 +127,12 @@ public:
|
|||
NEEDS_NEWLINE_NORMALIZATION = 0x02,
|
||||
NEEDS_WHITESPACE_COLLAPSING = 0x04,
|
||||
|
||||
TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
|
||||
TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
|
||||
TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
|
||||
ATTRIBUTE_NAME = 0,
|
||||
ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
|
||||
ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
|
||||
COMMENT = NEEDS_NEWLINE_NORMALIZATION
|
||||
ATTRIBUTE_NAME = 0,
|
||||
ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
|
||||
ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
|
||||
COMMENT = NEEDS_NEWLINE_NORMALIZATION
|
||||
};
|
||||
|
||||
StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
|
||||
|
@ -164,9 +164,9 @@ public:
|
|||
char* ParseName( char* in );
|
||||
|
||||
void TransferTo( StrPair* other );
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
void Reset();
|
||||
void CollapseWhitespace();
|
||||
|
||||
enum {
|
||||
|
@ -1759,11 +1759,11 @@ public:
|
|||
|
||||
/// Return a possibly helpful diagnostic location or string.
|
||||
const char* GetErrorStr1() const {
|
||||
return _errorStr1;
|
||||
return _errorStr1.GetStr();
|
||||
}
|
||||
/// Return a possibly helpful secondary diagnostic location or string.
|
||||
const char* GetErrorStr2() const {
|
||||
return _errorStr2;
|
||||
return _errorStr2.GetStr();
|
||||
}
|
||||
/// If there is an error, print it to stdout.
|
||||
void PrintError() const;
|
||||
|
@ -1789,8 +1789,8 @@ private:
|
|||
bool _processEntities;
|
||||
XMLError _errorID;
|
||||
Whitespace _whitespace;
|
||||
const char* _errorStr1;
|
||||
const char* _errorStr2;
|
||||
mutable StrPair _errorStr1;
|
||||
mutable StrPair _errorStr2;
|
||||
char* _charBuffer;
|
||||
|
||||
MemPoolT< sizeof(XMLElement) > _elementPool;
|
||||
|
|
Loading…
Reference in New Issue