Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 108cd60

Browse files
author
Davide Faconti
committed
updated tinyXML2. Should fix several issues too
1 parent fb40267 commit 108cd60

File tree

6 files changed

+221
-93
lines changed

6 files changed

+221
-93
lines changed

3rdparty/tinyXML2/CMakeLists.txt

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
IF(BIICODE)
2+
ADD_BIICODE_TARGETS()
3+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/resources)
4+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
5+
ENDIF()
6+
RETURN()
7+
ENDIF(BIICODE)
8+
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
9+
cmake_policy(VERSION 2.6)
10+
if(POLICY CMP0063)
11+
cmake_policy(SET CMP0063 OLD)
12+
endif()
13+
14+
project(tinyxml2)
15+
include(GNUInstallDirs)
16+
include(CTest)
17+
#enable_testing()
18+
19+
#CMAKE_BUILD_TOOL
20+
21+
################################
22+
# set lib version here
23+
24+
set(GENERIC_LIB_VERSION "7.0.1")
25+
set(GENERIC_LIB_SOVERSION "7")
26+
27+
################################
28+
# Add definitions
29+
30+
################################
31+
# Add targets
32+
# By Default shared library is being built
33+
# To build static libs also - Do cmake . -DBUILD_STATIC_LIBS:BOOL=ON
34+
# User can choose not to build shared library by using cmake -DBUILD_SHARED_LIBS:BOOL=OFF
35+
# To build only static libs use cmake . -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON
36+
# To build the tests, use cmake . -DBUILD_TESTS:BOOL=ON
37+
# To disable the building of the tests, use cmake . -DBUILD_TESTS:BOOL=OFF
38+
39+
add_definitions(-DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON)
40+
41+
# To allow using tinyxml in another shared library
42+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
43+
44+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
45+
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
46+
47+
# to distinguish between debug and release lib
48+
set(CMAKE_DEBUG_POSTFIX "d")
49+
50+
add_library(tinyxml2_v7 tinyxml2.cpp tinyxml2.h)
51+
52+
set_target_properties(tinyxml2_v7 PROPERTIES
53+
COMPILE_DEFINITIONS "TINYXML2_EXPORT"
54+
VERSION "${GENERIC_LIB_VERSION}"
55+
SOVERSION "${GENERIC_LIB_SOVERSION}")
56+
57+
target_compile_definitions(tinyxml2_v7 PUBLIC $<$<CONFIG:Debug>:TINYXML2_DEBUG>)
58+
59+
if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
60+
target_include_directories(tinyxml2_v7 PUBLIC
61+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
62+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
63+
64+
if(MSVC)
65+
target_compile_definitions(tinyxml2_v7 PUBLIC -D_CRT_SECURE_NO_WARNINGS)
66+
endif(MSVC)
67+
else()
68+
include_directories(${PROJECT_SOURCE_DIR})
69+
70+
if(MSVC)
71+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
72+
endif(MSVC)
73+
endif()
74+
75+
# export targets for find_package config mode
76+
export(TARGETS tinyxml2_v7
77+
FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)
78+
79+
install(TARGETS tinyxml2_v7
80+
EXPORT ${CMAKE_PROJECT_NAME}Targets
81+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
82+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
83+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
84+
85+
install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
86+
87+
configure_file(tinyxml2.pc.in tinyxml2.pc @ONLY)
88+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
89+
90+
include(CMakePackageConfigHelpers)
91+
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
92+
configure_package_config_file(
93+
"Config.cmake.in"
94+
"${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake"
95+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}"
96+
)
97+
install(FILES
98+
${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
99+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME})
100+
101+
install(EXPORT ${CMAKE_PROJECT_NAME}Targets NAMESPACE tinyxml2::
102+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME})

3rdparty/tinyXML2/Config.cmake.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
4+
check_required_components("@PROJECT_NAME@")

3rdparty/tinyXML2/tinyxml2.cpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,15 +1032,25 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
10321032
XMLDeclaration* decl = node->ToDeclaration();
10331033
if ( decl ) {
10341034
// Declarations are only allowed at document level
1035-
bool wellLocated = ( ToDocument() != 0 );
1036-
if ( wellLocated ) {
1037-
// Multiple declarations are allowed but all declarations
1038-
// must occur before anything else
1039-
for ( const XMLNode* existingNode = _document->FirstChild(); existingNode; existingNode = existingNode->NextSibling() ) {
1040-
if ( !existingNode->ToDeclaration() ) {
1041-
wellLocated = false;
1042-
break;
1043-
}
1035+
//
1036+
// Multiple declarations are allowed but all declarations
1037+
// must occur before anything else.
1038+
//
1039+
// Optimized due to a security test case. If the first node is
1040+
// a declaration, and the last node is a declaration, then only
1041+
// declarations have so far been addded.
1042+
bool wellLocated = false;
1043+
1044+
if (ToDocument()) {
1045+
if (FirstChild()) {
1046+
wellLocated =
1047+
FirstChild() &&
1048+
FirstChild()->ToDeclaration() &&
1049+
LastChild() &&
1050+
LastChild()->ToDeclaration();
1051+
}
1052+
else {
1053+
wellLocated = true;
10441054
}
10451055
}
10461056
if ( !wellLocated ) {
@@ -1977,10 +1987,8 @@ const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = {
19771987
"XML_ERROR_FILE_NOT_FOUND",
19781988
"XML_ERROR_FILE_COULD_NOT_BE_OPENED",
19791989
"XML_ERROR_FILE_READ_ERROR",
1980-
"UNUSED_XML_ERROR_ELEMENT_MISMATCH",
19811990
"XML_ERROR_PARSING_ELEMENT",
19821991
"XML_ERROR_PARSING_ATTRIBUTE",
1983-
"UNUSED_XML_ERROR_IDENTIFYING_TAG",
19841992
"XML_ERROR_PARSING_TEXT",
19851993
"XML_ERROR_PARSING_CDATA",
19861994
"XML_ERROR_PARSING_COMMENT",
@@ -2327,6 +2335,7 @@ void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ...
23272335
size_t BUFFER_SIZE = 1000;
23282336
char* buffer = new char[BUFFER_SIZE];
23292337

2338+
TIXMLASSERT(sizeof(error) <= sizeof(int));
23302339
TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d", ErrorIDToName(error), int(error), int(error), lineNum);
23312340

23322341
if (format) {
@@ -2523,14 +2532,16 @@ void XMLPrinter::PrintString( const char* p, bool restricted )
25232532
++q;
25242533
TIXMLASSERT( p <= q );
25252534
}
2535+
// Flush the remaining string. This will be the entire
2536+
// string if an entity wasn't found.
2537+
if ( p < q ) {
2538+
const size_t delta = q - p;
2539+
const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta;
2540+
Write( p, toPrint );
2541+
}
25262542
}
2527-
// Flush the remaining string. This will be the entire
2528-
// string if an entity wasn't found.
2529-
TIXMLASSERT( p <= q );
2530-
if ( !_processEntities || ( p < q ) ) {
2531-
const size_t delta = q - p;
2532-
const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta;
2533-
Write( p, toPrint );
2543+
else {
2544+
Write( p );
25342545
}
25352546
}
25362547

0 commit comments

Comments
 (0)