mirror of
https://github.com/AxioDL/tinyxml2.git
synced 2025-05-14 11:21:38 +00:00
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 ),
|
_processEntities( processEntities ),
|
||||||
_errorID(XML_SUCCESS),
|
_errorID(XML_SUCCESS),
|
||||||
_whitespace( whitespace ),
|
_whitespace( whitespace ),
|
||||||
_errorStr1( 0 ),
|
|
||||||
_errorStr2( 0 ),
|
|
||||||
_charBuffer( 0 )
|
_charBuffer( 0 )
|
||||||
{
|
{
|
||||||
// avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+)
|
// 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();
|
const bool hadError = Error();
|
||||||
#endif
|
#endif
|
||||||
_errorID = XML_SUCCESS;
|
_errorID = XML_SUCCESS;
|
||||||
_errorStr1 = 0;
|
_errorStr1.Reset();
|
||||||
_errorStr2 = 0;
|
_errorStr2.Reset();
|
||||||
|
|
||||||
delete [] _charBuffer;
|
delete [] _charBuffer;
|
||||||
_charBuffer = 0;
|
_charBuffer = 0;
|
||||||
@ -2112,8 +2110,14 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2 )
|
|||||||
{
|
{
|
||||||
TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT );
|
TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT );
|
||||||
_errorID = error;
|
_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
|
const char* XMLDocument::ErrorName() const
|
||||||
@ -2131,11 +2135,11 @@ void XMLDocument::PrintError() const
|
|||||||
char buf1[LEN] = { 0 };
|
char buf1[LEN] = { 0 };
|
||||||
char buf2[LEN] = { 0 };
|
char buf2[LEN] = { 0 };
|
||||||
|
|
||||||
if ( _errorStr1 ) {
|
if ( !_errorStr1.Empty() ) {
|
||||||
TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr1 );
|
TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr1.GetStr() );
|
||||||
}
|
}
|
||||||
if ( _errorStr2 ) {
|
if ( !_errorStr2.Empty() ) {
|
||||||
TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 );
|
TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2.GetStr() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should check INT_MIN <= _errorID && _errorId <= INT_MAX, but that
|
// Should check INT_MIN <= _errorID && _errorId <= INT_MAX, but that
|
||||||
|
10
tinyxml2.h
10
tinyxml2.h
@ -164,9 +164,9 @@ public:
|
|||||||
char* ParseName( char* in );
|
char* ParseName( char* in );
|
||||||
|
|
||||||
void TransferTo( StrPair* other );
|
void TransferTo( StrPair* other );
|
||||||
|
void Reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Reset();
|
|
||||||
void CollapseWhitespace();
|
void CollapseWhitespace();
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -1759,11 +1759,11 @@ public:
|
|||||||
|
|
||||||
/// Return a possibly helpful diagnostic location or string.
|
/// Return a possibly helpful diagnostic location or string.
|
||||||
const char* GetErrorStr1() const {
|
const char* GetErrorStr1() const {
|
||||||
return _errorStr1;
|
return _errorStr1.GetStr();
|
||||||
}
|
}
|
||||||
/// Return a possibly helpful secondary diagnostic location or string.
|
/// Return a possibly helpful secondary diagnostic location or string.
|
||||||
const char* GetErrorStr2() const {
|
const char* GetErrorStr2() const {
|
||||||
return _errorStr2;
|
return _errorStr2.GetStr();
|
||||||
}
|
}
|
||||||
/// If there is an error, print it to stdout.
|
/// If there is an error, print it to stdout.
|
||||||
void PrintError() const;
|
void PrintError() const;
|
||||||
@ -1789,8 +1789,8 @@ private:
|
|||||||
bool _processEntities;
|
bool _processEntities;
|
||||||
XMLError _errorID;
|
XMLError _errorID;
|
||||||
Whitespace _whitespace;
|
Whitespace _whitespace;
|
||||||
const char* _errorStr1;
|
mutable StrPair _errorStr1;
|
||||||
const char* _errorStr2;
|
mutable StrPair _errorStr2;
|
||||||
char* _charBuffer;
|
char* _charBuffer;
|
||||||
|
|
||||||
MemPoolT< sizeof(XMLElement) > _elementPool;
|
MemPoolT< sizeof(XMLElement) > _elementPool;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user