summaryrefslogtreecommitdiff
path: root/src/mir_core
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-05-22 11:11:03 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-05-22 11:11:03 +0300
commit3d89e5cc50b5bb79d69ae5bd6c8611fc4a2b0954 (patch)
tree1b34d2eea5de3e512f142e745018d864135598dc /src/mir_core
parent56358ea781acbbf3655e369e82507c55614c9b17 (diff)
fixes #2888 (Update TinyXML2 to 8.10)
Diffstat (limited to 'src/mir_core')
-rw-r--r--src/mir_core/src/mir_core.def9
-rw-r--r--src/mir_core/src/mir_core64.def9
-rw-r--r--src/mir_core/src/tinyxml2.cpp182
-rw-r--r--src/mir_core/src/tinyxml2.h43
4 files changed, 144 insertions, 99 deletions
diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def
index b5dd1fc756..7fadd95afe 100644
--- a/src/mir_core/src/mir_core.def
+++ b/src/mir_core/src/mir_core.def
@@ -1224,7 +1224,7 @@ db_event_edit @1268
?PreviousSiblingElement@XMLNode@tinyxml2@@QAEPAVXMLElement@2@PBD@Z @1444 NONAME
?PreviousSiblingElement@XMLNode@tinyxml2@@QBEPBVXMLElement@2@PBD@Z @1445 NONAME
?Print@XMLDocument@tinyxml2@@QBEXPAVXMLPrinter@2@@Z @1446 NONAME
-?Print@XMLPrinter@tinyxml2@@IAAXPBDZZ @1447 NONAME
+?Print@XMLPrinter@tinyxml2@@MAAXPBDZZ @1447 NONAME
?PrintError@XMLDocument@tinyxml2@@QBEXXZ @1448 NONAME
?PrintSpace@XMLPrinter@tinyxml2@@MAEXH@Z @1449 NONAME
?PrintString@XMLPrinter@tinyxml2@@AAEXPBD_N@Z @1450 NONAME
@@ -1247,7 +1247,7 @@ db_event_edit @1268
?PushText@XMLPrinter@tinyxml2@@QAEX_J@Z @1467 NONAME
?PushText@XMLPrinter@tinyxml2@@QAEX_N@Z @1468 NONAME
?PushUnknown@XMLPrinter@tinyxml2@@QAEXPBD@Z @1469 NONAME
-?Putc@XMLPrinter@tinyxml2@@IAEXD@Z @1470 NONAME
+?Putc@XMLPrinter@tinyxml2@@MAEXD@Z @1470 NONAME
?QueryAttribute@XMLElement@tinyxml2@@QBE?AW4XMLError@2@PBDPAH@Z @1471 NONAME
?QueryAttribute@XMLElement@tinyxml2@@QBE?AW4XMLError@2@PBDPAI@Z @1472 NONAME
?QueryAttribute@XMLElement@tinyxml2@@QBE?AW4XMLError@2@PBDPAM@Z @1473 NONAME
@@ -1399,7 +1399,7 @@ db_event_edit @1268
?VisitExit@XMLVisitor@tinyxml2@@UAE_NABVXMLElement@2@@Z @1619 NONAME
?WhitespaceMode@XMLDocument@tinyxml2@@QBE?AW4Whitespace@2@XZ @1620 NONAME
?Write@XMLPrinter@tinyxml2@@IAEXPBD@Z @1621 NONAME
-?Write@XMLPrinter@tinyxml2@@IAEXPBDI@Z @1622 NONAME
+?Write@XMLPrinter@tinyxml2@@MAEXPBDI@Z @1622 NONAME
?_errorNames@XMLDocument@tinyxml2@@0PAPBDA @1623 NONAME
?writeBoolFalse@XMLUtil@tinyxml2@@0PBDB @1624 NONAME
?writeBoolTrue@XMLUtil@tinyxml2@@0PBDB @1625 NONAME
@@ -1508,3 +1508,6 @@ TimeZone_GetSystemTime @1692
?GetCurData@CCtrlCombo@@QBEJXZ @1730 NONAME
?SetDraw@CCtrlBase@@QAEX_N@Z @1731 NONAME
?SetDraw@CDlgBase@@QAEX_N@Z @1732 NONAME
+?IsPrefixHex@XMLUtil@tinyxml2@@SA_NPBD@Z @1733 NONAME
+?PrepareForNewNode@XMLPrinter@tinyxml2@@AAEX_N@Z @1734 NONAME
+?QueryAttribute@XMLElement@tinyxml2@@QBE?AW4XMLError@2@PBDPAPBD@Z @1735 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def
index 41694e7d20..0996138663 100644
--- a/src/mir_core/src/mir_core64.def
+++ b/src/mir_core/src/mir_core64.def
@@ -1224,7 +1224,7 @@ db_event_edit @1268
?PreviousSiblingElement@XMLNode@tinyxml2@@QEAAPEAVXMLElement@2@PEBD@Z @1444 NONAME
?PreviousSiblingElement@XMLNode@tinyxml2@@QEBAPEBVXMLElement@2@PEBD@Z @1445 NONAME
?Print@XMLDocument@tinyxml2@@QEBAXPEAVXMLPrinter@2@@Z @1446 NONAME
-?Print@XMLPrinter@tinyxml2@@IEAAXPEBDZZ @1447 NONAME
+?Print@XMLPrinter@tinyxml2@@MEAAXPEBDZZ @1447 NONAME
?PrintError@XMLDocument@tinyxml2@@QEBAXXZ @1448 NONAME
?PrintSpace@XMLPrinter@tinyxml2@@MEAAXH@Z @1449 NONAME
?PrintString@XMLPrinter@tinyxml2@@AEAAXPEBD_N@Z @1450 NONAME
@@ -1247,7 +1247,7 @@ db_event_edit @1268
?PushText@XMLPrinter@tinyxml2@@QEAAX_J@Z @1467 NONAME
?PushText@XMLPrinter@tinyxml2@@QEAAX_N@Z @1468 NONAME
?PushUnknown@XMLPrinter@tinyxml2@@QEAAXPEBD@Z @1469 NONAME
-?Putc@XMLPrinter@tinyxml2@@IEAAXD@Z @1470 NONAME
+?Putc@XMLPrinter@tinyxml2@@MEAAXD@Z @1470 NONAME
?QueryAttribute@XMLElement@tinyxml2@@QEBA?AW4XMLError@2@PEBDPEAH@Z @1471 NONAME
?QueryAttribute@XMLElement@tinyxml2@@QEBA?AW4XMLError@2@PEBDPEAI@Z @1472 NONAME
?QueryAttribute@XMLElement@tinyxml2@@QEBA?AW4XMLError@2@PEBDPEAM@Z @1473 NONAME
@@ -1399,7 +1399,7 @@ db_event_edit @1268
?VisitExit@XMLVisitor@tinyxml2@@UEAA_NAEBVXMLElement@2@@Z @1619 NONAME
?WhitespaceMode@XMLDocument@tinyxml2@@QEBA?AW4Whitespace@2@XZ @1620 NONAME
?Write@XMLPrinter@tinyxml2@@IEAAXPEBD@Z @1621 NONAME
-?Write@XMLPrinter@tinyxml2@@IEAAXPEBD_K@Z @1622 NONAME
+?Write@XMLPrinter@tinyxml2@@MEAAXPEBD_K@Z @1622 NONAME
?_errorNames@XMLDocument@tinyxml2@@0PAPEBDA @1623 NONAME
?writeBoolFalse@XMLUtil@tinyxml2@@0PEBDEB @1624 NONAME
?writeBoolTrue@XMLUtil@tinyxml2@@0PEBDEB @1625 NONAME
@@ -1508,3 +1508,6 @@ TimeZone_GetSystemTime @1692
?GetCurData@CCtrlCombo@@QEBA_JXZ @1730 NONAME
?SetDraw@CCtrlBase@@QEAAX_N@Z @1731 NONAME
?SetDraw@CDlgBase@@QEAAX_N@Z @1732 NONAME
+?IsPrefixHex@XMLUtil@tinyxml2@@SA_NPEBD@Z @1733 NONAME
+?PrepareForNewNode@XMLPrinter@tinyxml2@@AEAAX_N@Z @1734 NONAME
+?QueryAttribute@XMLElement@tinyxml2@@QEBA?AW4XMLError@2@PEBDPEAPEBD@Z @1735 NONAME
diff --git a/src/mir_core/src/tinyxml2.cpp b/src/mir_core/src/tinyxml2.cpp
index 919ffa30bd..cf94910d97 100644
--- a/src/mir_core/src/tinyxml2.cpp
+++ b/src/mir_core/src/tinyxml2.cpp
@@ -100,6 +100,20 @@ distribution.
#define TIXML_SSCANF sscanf
#endif
+#if defined(_WIN64)
+ #define TIXML_FSEEK _fseeki64
+ #define TIXML_FTELL _ftelli64
+#elif defined(__APPLE__) || defined(__FreeBSD__)
+ #define TIXML_FSEEK fseeko
+ #define TIXML_FTELL ftello
+#elif defined(__unix__) && defined(__x86_64__)
+ #define TIXML_FSEEK fseeko64
+ #define TIXML_FTELL ftello64
+#else
+ #define TIXML_FSEEK fseek
+ #define TIXML_FTELL ftell
+#endif
+
static const char LINE_FEED = static_cast<char>(0x0a); // all line endings are normalized to LF
static const char LF = LINE_FEED;
@@ -220,13 +234,13 @@ char* StrPair::ParseName( char* p )
if ( !p || !(*p) ) {
return 0;
}
- if ( !XMLUtil::IsNameStartChar( *p ) ) {
+ if ( !XMLUtil::IsNameStartChar( (unsigned char) *p ) ) {
return 0;
}
char* const start = p;
++p;
- while ( *p && XMLUtil::IsNameChar( *p ) ) {
+ while ( *p && XMLUtil::IsNameChar( (unsigned char) *p ) ) {
++p;
}
@@ -594,17 +608,26 @@ void XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize )
TIXML_SNPRINTF(buffer, bufferSize, "%llu", (long long)v);
}
-bool XMLUtil::ToInt( const char* str, int* value )
+bool XMLUtil::ToInt(const char* str, int* value)
{
- if ( TIXML_SSCANF( str, "%d", value ) == 1 ) {
- return true;
+ if (IsPrefixHex(str)) {
+ unsigned v;
+ if (TIXML_SSCANF(str, "%x", &v) == 1) {
+ *value = static_cast<int>(v);
+ return true;
+ }
+ }
+ else {
+ if (TIXML_SSCANF(str, "%d", value) == 1) {
+ return true;
+ }
}
return false;
}
-bool XMLUtil::ToUnsigned( const char* str, unsigned *value )
+bool XMLUtil::ToUnsigned(const char* str, unsigned* value)
{
- if ( TIXML_SSCANF( str, "%u", value ) == 1 ) {
+ if (TIXML_SSCANF(str, IsPrefixHex(str) ? "%x" : "%u", value) == 1) {
return true;
}
return false;
@@ -656,18 +679,27 @@ bool XMLUtil::ToDouble( const char* str, double* value )
bool XMLUtil::ToInt64(const char* str, int64_t* value)
{
- long long v = 0; // horrible syntax trick to make the compiler happy about %lld
- if (TIXML_SSCANF(str, "%lld", &v) == 1) {
- *value = static_cast<int64_t>(v);
- return true;
- }
+ if (IsPrefixHex(str)) {
+ unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llx
+ if (TIXML_SSCANF(str, "%llx", &v) == 1) {
+ *value = static_cast<int64_t>(v);
+ return true;
+ }
+ }
+ else {
+ long long v = 0; // horrible syntax trick to make the compiler happy about %lld
+ if (TIXML_SSCANF(str, "%lld", &v) == 1) {
+ *value = static_cast<int64_t>(v);
+ return true;
+ }
+ }
return false;
}
bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) {
unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llu
- if(TIXML_SSCANF(str, "%llu", &v) == 1) {
+ if(TIXML_SSCANF(str, IsPrefixHex(str) ? "%llx" : "%llu", &v) == 1) {
*value = (uint64_t)v;
return true;
}
@@ -1631,8 +1663,18 @@ float XMLElement::FloatAttribute(const char* name, float defaultValue) const
const char* XMLElement::GetText() const
{
- if ( FirstChild() && FirstChild()->ToText() ) {
- return FirstChild()->Value();
+ /* skip comment node */
+ const XMLNode* node = FirstChild();
+ while (node) {
+ if (node->ToComment()) {
+ node = node->NextSibling();
+ continue;
+ }
+ break;
+ }
+
+ if ( node && node->ToText() ) {
+ return node->Value();
}
return 0;
}
@@ -1909,7 +1951,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr )
}
// attribute.
- if (XMLUtil::IsNameStartChar( *p ) ) {
+ if (XMLUtil::IsNameStartChar( (unsigned char) *p ) ) {
XMLAttribute* attrib = CreateAttribute();
TIXMLASSERT( attrib );
attrib->_parseLineNum = _document->_parseCurLineNum;
@@ -1917,17 +1959,11 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr )
const int attrLineNum = attrib->_parseLineNum;
p = attrib->ParseDeep( p, _document->ProcessEntities(), curLineNumPtr );
- if ( !p ) {
+ if ( !p || Attribute( attrib->Name() ) ) {
DeleteAttribute( attrib );
_document->SetError( XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, "XMLElement name=%s", Name() );
return 0;
}
-
- if (Attribute(attrib->Name())) {
- DeleteAttribute(attrib);
- continue;
- }
-
// There is a minor bug here: if the attribute in the source xml
// document is duplicated, it will not be detected and the
// attribute will be doubly added. However, tracking the 'prevAttribute'
@@ -2306,49 +2342,34 @@ XMLError XMLDocument::LoadFile( const char* filename )
return _errorID;
}
-// This is likely overengineered template art to have a check that unsigned long value incremented
-// by one still fits into size_t. If size_t type is larger than unsigned long type
-// (x86_64-w64-mingw32 target) then the check is redundant and gcc and clang emit
-// -Wtype-limits warning. This piece makes the compiler select code with a check when a check
-// is useful and code with no check when a check is redundant depending on how size_t and unsigned long
-// types sizes relate to each other.
-template
-<bool = (sizeof(unsigned long) >= sizeof(size_t))>
-struct LongFitsIntoSizeTMinusOne {
- static bool Fits( unsigned long value )
- {
- return value < static_cast<size_t>(-1);
- }
-};
-
-template <>
-struct LongFitsIntoSizeTMinusOne<false> {
- static bool Fits( unsigned long )
- {
- return true;
- }
-};
-
XMLError XMLDocument::LoadFile( FILE* fp )
{
Clear();
- fseek( fp, 0, SEEK_SET );
+ TIXML_FSEEK( fp, 0, SEEK_SET );
if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) {
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return _errorID;
}
- fseek( fp, 0, SEEK_END );
- const long filelength = ftell( fp );
- fseek( fp, 0, SEEK_SET );
- if ( filelength == -1L ) {
- SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
- return _errorID;
+ TIXML_FSEEK( fp, 0, SEEK_END );
+
+ unsigned long long filelength;
+ {
+ const long long fileLengthSigned = TIXML_FTELL( fp );
+ TIXML_FSEEK( fp, 0, SEEK_SET );
+ if ( fileLengthSigned == -1L ) {
+ SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
+ return _errorID;
+ }
+ TIXMLASSERT( fileLengthSigned >= 0 );
+ filelength = static_cast<unsigned long long>(fileLengthSigned);
}
- TIXMLASSERT( filelength >= 0 );
- if ( !LongFitsIntoSizeTMinusOne<>::Fits( filelength ) ) {
+ const size_t maxSizeT = static_cast<size_t>(-1);
+ // We'll do the comparison as an unsigned long long, because that's guaranteed to be at
+ // least 8 bytes, even on a 32-bit platform.
+ if ( filelength >= static_cast<unsigned long long>(maxSizeT) ) {
// Cannot handle files which won't fit in buffer together with null terminator
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return _errorID;
@@ -2359,7 +2380,7 @@ XMLError XMLDocument::LoadFile( FILE* fp )
return _errorID;
}
- const size_t size = filelength;
+ const size_t size = static_cast<size_t>(filelength);
TIXMLASSERT( _charBuffer == 0 );
_charBuffer = new char[size+1];
const size_t read = fread( _charBuffer, 1, size, fp );
@@ -2448,6 +2469,13 @@ void XMLDocument::Print( XMLPrinter* streamer ) const
}
+void XMLDocument::ClearError() {
+ _errorID = XML_SUCCESS;
+ _errorLineNum = 0;
+ _errorStr.Reset();
+}
+
+
void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... )
{
TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT );
@@ -2681,22 +2709,33 @@ void XMLPrinter::PushHeader( bool writeBOM, bool writeDec )
}
}
-
-void XMLPrinter::OpenElement( const char* name, bool compactMode )
+void XMLPrinter::PrepareForNewNode( bool compactMode )
{
SealElementIfJustOpened();
- _stack.Push( name );
- if ( _textDepth < 0 && !_firstElement && !compactMode ) {
+ if ( compactMode ) {
+ return;
+ }
+
+ if ( _firstElement ) {
+ PrintSpace (_depth);
+ } else if ( _textDepth < 0) {
Putc( '\n' );
PrintSpace( _depth );
}
+ _firstElement = false;
+}
+
+void XMLPrinter::OpenElement( const char* name, bool compactMode )
+{
+ PrepareForNewNode( compactMode );
+ _stack.Push( name );
+
Write ( "<" );
Write ( name );
_elementJustOpened = true;
- _firstElement = false;
++_depth;
}
@@ -2872,12 +2911,7 @@ void XMLPrinter::PushText( double value )
void XMLPrinter::PushComment( const char* comment )
{
- SealElementIfJustOpened();
- if ( _textDepth < 0 && !_firstElement && !_compactMode) {
- Putc( '\n' );
- PrintSpace( _depth );
- }
- _firstElement = false;
+ PrepareForNewNode( _compactMode );
Write( "<!--" );
Write( comment );
@@ -2887,12 +2921,7 @@ void XMLPrinter::PushComment( const char* comment )
void XMLPrinter::PushDeclaration( const char* value )
{
- SealElementIfJustOpened();
- if ( _textDepth < 0 && !_firstElement && !_compactMode) {
- Putc( '\n' );
- PrintSpace( _depth );
- }
- _firstElement = false;
+ PrepareForNewNode( _compactMode );
Write( "<?" );
Write( value );
@@ -2902,12 +2931,7 @@ void XMLPrinter::PushDeclaration( const char* value )
void XMLPrinter::PushUnknown( const char* value )
{
- SealElementIfJustOpened();
- if ( _textDepth < 0 && !_firstElement && !_compactMode) {
- Putc( '\n' );
- PrintSpace( _depth );
- }
- _firstElement = false;
+ PrepareForNewNode( _compactMode );
Write( "<!" );
Write( value );
diff --git a/src/mir_core/src/tinyxml2.h b/src/mir_core/src/tinyxml2.h
index 7d5a151e67..01040aeb90 100644
--- a/src/mir_core/src/tinyxml2.h
+++ b/src/mir_core/src/tinyxml2.h
@@ -79,6 +79,7 @@ distribution.
#endif
+#if !defined(TIXMLASSERT)
#if defined(TINYXML2_DEBUG)
# if defined(_MSC_VER)
# // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
@@ -93,17 +94,17 @@ distribution.
#else
# define TIXMLASSERT( x ) {}
#endif
-
+#endif
/* Versioning, past 1.0.14:
http://semver.org/
*/
static const int TIXML2_MAJOR_VERSION = 8;
-static const int TIXML2_MINOR_VERSION = 0;
+static const int TIXML2_MINOR_VERSION = 1;
static const int TIXML2_PATCH_VERSION = 0;
#define TINYXML2_MAJOR_VERSION 8
-#define TINYXML2_MINOR_VERSION 0
+#define TINYXML2_MINOR_VERSION 1
#define TINYXML2_PATCH_VERSION 0
// A fixed element depth limit is problematic. There needs to be a
@@ -135,7 +136,7 @@ class XMLPrinter;
class TINYXML2_LIB StrPair
{
public:
- enum {
+ enum Mode {
NEEDS_ENTITY_PROCESSING = 0x01,
NEEDS_NEWLINE_NORMALIZATION = 0x02,
NEEDS_WHITESPACE_COLLAPSING = 0x04,
@@ -590,6 +591,11 @@ public:
|| ch == '-';
}
+ inline static bool IsPrefixHex( const char* p) {
+ p = SkipWhiteSpace(p, 0);
+ return p && *p == '0' && ( *(p + 1) == 'x' || *(p + 1) == 'X');
+ }
+
inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
if ( p == q ) {
return true;
@@ -1214,8 +1220,8 @@ public:
/// See QueryIntValue
XMLError QueryFloatValue( float* value ) const;
- /// Set the attribute to a string value.
- void SetAttribute( const char* value );
+ /// Set the attribute to a string value.
+ void SetAttribute( const char* value );
/// Set the attribute to a wide string value.
void SetAttribute( const wchar_t* value );
/// Set the attribute to value.
@@ -1453,6 +1459,10 @@ public:
return QueryFloatAttribute( name, value );
}
+ XMLError QueryAttribute(const char* name, const char** value) const {
+ return QueryStringAttribute(name, value);
+ }
+
/// Sets the named attribute to value.
void SetAttribute( const char* name, const char* value ) {
XMLAttribute* a = FindOrCreateAttribute( name );
@@ -1484,7 +1494,7 @@ public:
XMLAttribute* a = FindOrCreateAttribute(name);
a->SetAttribute(value);
}
-
+
/// Sets the named attribute to value.
void SetAttribute( const char* name, bool value ) {
XMLAttribute* a = FindOrCreateAttribute( name );
@@ -1874,9 +1884,8 @@ public:
*/
void DeleteNode( XMLNode* node );
- void ClearError() {
- SetError(XML_SUCCESS, 0, 0);
- }
+ /// Clears the error flags.
+ void ClearError();
/// Return true if there was an error parsing the document.
bool Error() const {
@@ -2341,16 +2350,22 @@ protected:
the space and tabs used. A PrintSpace() override should call Print().
*/
virtual void PrintSpace( int depth );
- void Print( const char* format, ... );
- void Write( const char* data, size_t size );
- inline void Write( const char* data ) { Write( data, strlen( data ) ); }
- void Putc( char ch );
+ virtual void Print( const char* format, ... );
+ virtual void Write( const char* data, size_t size );
+ virtual void Putc( char ch );
+
+ inline void Write(const char* data) { Write(data, strlen(data)); }
void SealElementIfJustOpened();
bool _elementJustOpened;
DynArray< const char*, 10 > _stack;
private:
+ /**
+ Prepares to write a new node. This includes sealing an element that was
+ just opened, and writing any whitespace necessary if not in compact mode.
+ */
+ void PrepareForNewNode( bool compactMode );
void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
bool _firstElement;