From 3d89e5cc50b5bb79d69ae5bd6c8611fc4a2b0954 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 22 May 2021 11:11:03 +0300 Subject: fixes #2888 (Update TinyXML2 to 8.10) --- libs/win32/mir_core.lib | Bin 478654 -> 479798 bytes libs/win64/mir_core.lib | Bin 483812 -> 484988 bytes src/mir_core/src/mir_core.def | 9 +- src/mir_core/src/mir_core64.def | 9 +- src/mir_core/src/tinyxml2.cpp | 182 +++++++++++++++++++++++----------------- src/mir_core/src/tinyxml2.h | 43 ++++++---- 6 files changed, 144 insertions(+), 99 deletions(-) diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib index f822dbb8b3..9ffb9f0375 100644 Binary files a/libs/win32/mir_core.lib and b/libs/win32/mir_core.lib differ diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib index 401f44989c..6129aa8eee 100644 Binary files a/libs/win64/mir_core.lib and b/libs/win64/mir_core.lib differ 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(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(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(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(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(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 -= sizeof(size_t))> -struct LongFitsIntoSizeTMinusOne { - static bool Fits( unsigned long value ) - { - return value < static_cast(-1); - } -}; - -template <> -struct LongFitsIntoSizeTMinusOne { - 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(fileLengthSigned); } - TIXMLASSERT( filelength >= 0 ); - if ( !LongFitsIntoSizeTMinusOne<>::Fits( filelength ) ) { + const size_t maxSizeT = static_cast(-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(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(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( "