39 Commits
6.2.0 ... 7.0.0

Author SHA1 Message Date
Lee Thomason
397f22581b setting the version to 7.0.0 2018-11-06 09:37:43 -08:00
Lee Thomason
dcedec857b Merge pull request #718 from bolry/patch-1
Correct assigment interface for StrPair
2018-11-06 09:10:21 -08:00
Lee Thomason
992e405384 Merge pull request #716 from Dmitry-Me/fixInt64Slicing
Fix slicing of int64_t
2018-11-06 09:09:57 -08:00
Lee Thomason
de6f6616cd Merge pull request #715 from Dmitry-Me/checkLastChildBeforeInsertion
Check the element is the last child of the document
2018-11-06 09:09:05 -08:00
Lee Thomason
b894947c94 Merge pull request #714 from Masadow/pic
Add support for position independant code compilation
2018-11-06 09:08:35 -08:00
Bo Rydberg
65c1b86582 Correct assigment interface for StrPair
Assigment operator takes non-const reference when const reference is the norm.
2018-10-19 18:45:53 +02:00
Dmitry-Me
ed3e9dc82e Fix slicing of int64_t 2018-10-17 00:27:33 +03:00
Dmitry-Me
1781494391 Check the element is the last child of the document 2018-10-16 00:11:39 +03:00
Masadow
4be5bc8059 Add support for position independant code compilation 2018-10-09 14:57:44 +02:00
Lee Thomason
7e8e249990 Merge pull request #707 from SwiftEngineering/issue_706
Issue_706: Make resources path relative to current source and binary dir
2018-09-30 17:16:57 -07:00
Lee Thomason
25b23b88e1 Merge pull request #703 from orbitcowboy/master
Added explicit-keyword to constructors having 1 argument.
2018-09-30 17:16:13 -07:00
Jacob Schloss
ade41cdfe9 Make resources folder for xml test relative to current source and binary directory 2018-09-20 13:27:40 -07:00
orbitcowboy
2cc8a4c712 Added explicit-keyword to constructors having 1 argument. 2018-09-05 08:46:21 +02:00
Lee Thomason
c07409b5c3 remove virtual call in destruction 2018-08-25 11:04:13 -07:00
Lee Thomason
3be5d2b74b Merge pull request #695 from leethomason/manydecs
Many declarations
2018-08-25 10:54:54 -07:00
Lee Thomason
92506ca698 Merge remote-tracking branch 'origin/master' into manydecs 2018-08-05 17:33:11 -07:00
Lee Thomason
baf8bc93a7 Merge pull request #690 from orbitcowboy/master
Fixed typos in comments. There are no functional changes intended.
2018-08-05 17:31:42 -07:00
Lee Thomason
db13a82e62 fix huge number of declaration security issue 2018-07-28 14:56:20 -07:00
orbitcowboy
22b21ec9bc Fixed typos in comments. There are no functional changes intended. 2018-07-17 11:52:57 +02:00
Lee Thomason
c483646db0 fix test cases 2018-06-29 15:57:55 -07:00
Lee Thomason
93a8fb18ea Merge branch 'issue647' 2018-06-29 15:53:32 -07:00
Lee Thomason
92fc089e17 remove deprecated errors. next version will be major. 2018-06-29 15:51:37 -07:00
Lee Thomason
9f14aca07f Merge pull request #645 from jasjuang/master
fix sidenote on issue #588
2018-06-29 15:48:03 -07:00
Lee Thomason
30d0c3d5f2 add assertion 2018-06-29 15:47:37 -07:00
Lee Thomason
2bdb13ae5e Merge pull request #686 from leethomason/issue647
Fix Query return type
2018-06-29 15:42:28 -07:00
Lee Thomason
233b2cb820 Merge pull request #685 from leethomason/deadcode
Remove dead yet conflicting method
2018-06-29 15:38:35 -07:00
Lee Thomason
fc80df3b39 fix query return type 2018-06-29 15:37:29 -07:00
Lee Thomason
70d942e307 remove dead yet conflicting method 2018-06-29 15:31:59 -07:00
Lee Thomason
1cc174c2da Merge pull request #682 from lsolanka/pr.unify-cmake-build
Unify the CMake targets for static and shared libraries
2018-06-29 15:15:28 -07:00
Lukas Solanka
1b029f2bdd add target_compile_definitions 2018-06-25 23:01:22 +01:00
Lukas Solanka
392ec18324 use configure_package_config_file() 2018-06-25 23:01:22 +01:00
Lukas Solanka
b7c169ccbc Replace absolute installation paths with relative 2018-06-25 23:01:22 +01:00
Lee Thomason
c0ff869500 Merge pull request #681 from johnb003/patch-1
CMakeLists.txt support for relocatable installs
2018-06-25 11:41:01 -07:00
John Butterfield
d89d6d9551 Updated CMakeLists.txt for relocatable installs
Forcing CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_INCLUDEDIR to be absolute is unnecessary and results in absolute paths in the installation. This prevents relocatable prefix installations.
2018-06-20 18:58:09 -07:00
John Butterfield
b54cf3cb45 Made CMakeLists.txt installation relocatable.
The installation interface should really be a relative path.
2018-06-20 18:52:24 -07:00
Lee Thomason
a1d462d335 Merge pull request #670 from dquam/ProcessEntitiesBugWhenFalse
In PrintString, move the optimization under the if ( _processEntities…
2018-05-17 11:30:22 -07:00
Derek Quam
be69ae6352 In PrintString, move the optimization under the if ( _processEntities ) block and retain the strlen Write in the new else block. Added a test case. 2018-04-18 13:40:55 -05:00
Lee Thomason
3cdaf8b15e update the readme 2018-04-06 15:49:47 -07:00
jasjuang
ecbc16ae48 add namespace for cmake export 2018-03-23 09:52:19 -07:00
9 changed files with 220 additions and 238 deletions

View File

@@ -21,17 +21,15 @@ include(CTest)
################################
# set lib version here
set(GENERIC_LIB_VERSION "6.2.0")
set(GENERIC_LIB_SOVERSION "6")
set(GENERIC_LIB_VERSION "7.0.0")
set(GENERIC_LIB_SOVERSION "7")
################################
# Add definitions
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DTINYXML2_DEBUG")
################################
# Add targets
# By Default shared libray is being built
# By Default shared library is being built
# To build static libs also - Do cmake . -DBUILD_STATIC_LIBS:BOOL=ON
# User can choose not to build shared library by using cmake -DBUILD_SHARED_LIBS:BOOL=OFF
# To build only static libs use cmake . -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON
@@ -39,28 +37,30 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DTINYXML2_DEBUG")
# To disable the building of the tests, use cmake . -DBUILD_TESTS:BOOL=OFF
option(BUILD_SHARED_LIBS "build as shared library" ON)
option(BUILD_STATIC_LIBS "build as static library" OFF)
option(BUILD_TESTS "build xmltest (deprecated: Use BUILD_TESTING)" ON)
# To allow using tinyxml in another shared library
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
# to distinguish between debug and release lib
set(CMAKE_DEBUG_POSTFIX "d")
if(BUILD_SHARED_LIBS)
add_library(tinyxml2 SHARED tinyxml2.cpp tinyxml2.h)
add_library(tinyxml2 tinyxml2.cpp tinyxml2.h)
set_target_properties(tinyxml2 PROPERTIES
COMPILE_DEFINITIONS "TINYXML2_EXPORT"
VERSION "${GENERIC_LIB_VERSION}"
SOVERSION "${GENERIC_LIB_SOVERSION}")
target_compile_definitions(tinyxml2 PUBLIC $<$<CONFIG:Debug>:TINYXML2_DEBUG>)
if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_include_directories(tinyxml2 PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
if(MSVC)
target_compile_definitions(tinyxml2 PUBLIC -D_CRT_SECURE_NO_WARNINGS)
@@ -82,60 +82,17 @@ install(TARGETS tinyxml2
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if(BUILD_STATIC_LIBS)
add_library(tinyxml2_static STATIC tinyxml2.cpp tinyxml2.h)
set_target_properties(tinyxml2_static PROPERTIES
COMPILE_DEFINITONS "TINYXML2_EXPORT"
VERSION "${GENERIC_LIB_VERSION}"
SOVERSION "${GENERIC_LIB_SOVERSION}")
set_target_properties( tinyxml2_static PROPERTIES OUTPUT_NAME tinyxml2 )
target_compile_definitions(tinyxml2_static PUBLIC -D_CRT_SECURE_NO_WARNINGS)
if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_include_directories(tinyxml2_static PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
if(MSVC)
target_compile_definitions(tinyxml2_static PUBLIC -D_CRT_SECURE_NO_WARNINGS)
endif(MSVC)
else()
include_directories(${PROJECT_SOURCE_DIR})
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif(MSVC)
endif()
# export targets for find_package config mode
export(TARGETS tinyxml2_static
FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)
install(TARGETS tinyxml2_static
EXPORT ${CMAKE_PROJECT_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if(BUILD_TESTING AND BUILD_TESTS)
add_executable(xmltest xmltest.cpp)
if(BUILD_SHARED_LIBS)
add_dependencies(xmltest tinyxml2)
target_link_libraries(xmltest tinyxml2)
else(BUILD_STATIC_LIBS)
add_dependencies(xmltest tinyxml2_static)
target_link_libraries(xmltest tinyxml2_static)
endif()
add_dependencies(xmltest tinyxml2)
target_link_libraries(xmltest tinyxml2)
# Copy test resources and create test output directory
add_custom_command(TARGET xmltest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/resources $<TARGET_FILE_DIR:xmltest>/resources
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/resources $<TARGET_FILE_DIR:xmltest>/resources
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:xmltest>/resources/out
COMMENT "Configuring xmltest resources directory: ${CMAKE_BINARY_DIR}/resources"
COMMENT "Configuring xmltest resources directory: ${CMAKE_CURRENT_BINARY_DIR}/resources"
)
add_test(NAME xmltest COMMAND xmltest WORKING_DIRECTORY $<TARGET_FILE_DIR:xmltest>)
@@ -143,13 +100,6 @@ endif()
install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
foreach(p LIB INCLUDE)
set(var CMAKE_INSTALL_${p}DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
endforeach()
configure_file(tinyxml2.pc.in tinyxml2.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
@@ -164,13 +114,16 @@ if(NOT TARGET uninstall)
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
file(WRITE
${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
"include(\${CMAKE_CURRENT_LIST_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)\n")
include(CMakePackageConfigHelpers)
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
configure_package_config_file(
"Config.cmake.in"
"${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}"
)
install(FILES
${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME})
install(EXPORT ${CMAKE_PROJECT_NAME}Targets
install(EXPORT ${CMAKE_PROJECT_NAME}Targets NAMESPACE tinyxml2::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME})

4
Config.cmake.in Normal file
View File

@@ -0,0 +1,4 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
check_required_components("@PROJECT_NAME@")

View File

@@ -10,6 +10,7 @@ ARFLAGS = cr
RM = rm -f
RANLIB = ranlib
MKDIR = mkdir -p
CXXFLAGS = -fPIC
INSTALL = install
INSTALL_PROGRAM = $(INSTALL)

4
dox
View File

@@ -39,9 +39,9 @@ PROJECT_NAME = "TinyXML-2"
# control system is used.
<<<<<<< HEAD
PROJECT_NUMBER = 6.2.0
PROJECT_NUMBER = 7.0.0
=======
PROJECT_NUMBER = 6.2.0
PROJECT_NUMBER = 7.0.0
>>>>>>> master
# Using the PROJECT_BRIEF tag one can provide an optional one line description

View File

@@ -63,40 +63,28 @@ TinyXML-1 vs. TinyXML-2
-----------------------
TinyXML-2 is now the focus of all development, well tested, and your
best choice unless you have a requirement to maintain TinyXML-1 code.
best choice between the two APIs. At this point, unless you are maintaining
legacy code, you should choose TinyXML-2.
TinyXML-2 uses a similar API to TinyXML-1 and the same
rich test cases. But the implementation of the parser is completely re-written
to make it more appropriate for use in a game. It uses less memory, is faster,
and uses far fewer memory allocations.
TinyXML-2 has no requirement for STL, but has also dropped all STL support. All
strings are query and set as 'const char*'. This allows the use of internal
allocators, and keeps the code much simpler.
Both parsers:
1. Simple to use with similar APIs.
2. DOM based parser.
3. UTF-8 Unicode support. http://en.wikipedia.org/wiki/UTF-8
Advantages of TinyXML-2
1. The focus of all future dev.
2. Many fewer memory allocation (1/10th to 1/100th), uses less memory
(about 40% of TinyXML-1), and faster.
3. No STL requirement.
4. More modern C++, including a proper namespace.
5. Proper and useful handling of whitespace
Advantages of TinyXML-1
1. Support for some C++ STL conventions: streams and strings
2. Very mature and well debugged code base.
TinyXML-2 has no requirement or support for STL. By returning `const char*`
TinyXML-2 can be much more efficient with memory usage. (TinyXML-1 did support
and use STL, but consumed much more memory for the DOM representation.)
Features
--------
### Code Page
TinyXML-2 uses UTF-8 exclusively when interpreting XML. All XML is assumed to
be UTF-8.
Filenames for loading / saving are passed unchanged to the underlying OS.
### Memory Model
An XMLDocument is a C++ object like any other, that can be on the stack, or
@@ -166,7 +154,7 @@ cannot be parsed correctly. In addition, all nodes (elements, declarations,
text, comments etc.) and attributes have a line number recorded as they are parsed.
This allows an application that performs additional validation of the parsed
XML document (e.g. application-implemented DTD validation) to report
line number information in it's errors.
line number information for error messages.
### Entities
@@ -275,10 +263,10 @@ There are 2 files in TinyXML-2:
And additionally a test file:
* xmltest.cpp
Simply compile and run. There is a visual studio 2015 project included, a simple Makefile,
Simply compile and run. There is a visual studio 2017 project included, a simple Makefile,
an Xcode project, a Code::Blocks project, and a cmake CMakeLists.txt included to help you.
The top of tinyxml.h even has a simple g++ command line if you are are *nix and don't want
to use a build system.
The top of tinyxml.h even has a simple g++ command line if you are are Unix/Linuk/BSD and
don't want to use a build system.
Versioning
----------

File diff suppressed because one or more lines are too long

View File

@@ -1032,15 +1032,25 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
XMLDeclaration* decl = node->ToDeclaration();
if ( decl ) {
// Declarations are only allowed at document level
bool wellLocated = ( ToDocument() != 0 );
if ( wellLocated ) {
// Multiple declarations are allowed but all declarations
// must occur before anything else
for ( const XMLNode* existingNode = _document->FirstChild(); existingNode; existingNode = existingNode->NextSibling() ) {
if ( !existingNode->ToDeclaration() ) {
wellLocated = false;
break;
}
//
// Multiple declarations are allowed but all declarations
// must occur before anything else.
//
// Optimized due to a security test case. If the first node is
// a declaration, and the last node is a declaration, then only
// declarations have so far been addded.
bool wellLocated = false;
if (ToDocument()) {
if (FirstChild()) {
wellLocated =
FirstChild() &&
FirstChild()->ToDeclaration() &&
LastChild() &&
LastChild()->ToDeclaration();
}
else {
wellLocated = true;
}
}
if ( !wellLocated ) {
@@ -1977,10 +1987,8 @@ const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = {
"XML_ERROR_FILE_NOT_FOUND",
"XML_ERROR_FILE_COULD_NOT_BE_OPENED",
"XML_ERROR_FILE_READ_ERROR",
"UNUSED_XML_ERROR_ELEMENT_MISMATCH",
"XML_ERROR_PARSING_ELEMENT",
"XML_ERROR_PARSING_ATTRIBUTE",
"UNUSED_XML_ERROR_IDENTIFYING_TAG",
"XML_ERROR_PARSING_TEXT",
"XML_ERROR_PARSING_CDATA",
"XML_ERROR_PARSING_COMMENT",
@@ -2327,6 +2335,7 @@ void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ...
size_t BUFFER_SIZE = 1000;
char* buffer = new char[BUFFER_SIZE];
TIXMLASSERT(sizeof(error) <= sizeof(int));
TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d", ErrorIDToName(error), int(error), int(error), lineNum);
if (format) {
@@ -2523,14 +2532,16 @@ void XMLPrinter::PrintString( const char* p, bool restricted )
++q;
TIXMLASSERT( p <= q );
}
// Flush the remaining string. This will be the entire
// string if an entity wasn't found.
if ( p < q ) {
const size_t delta = q - p;
const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta;
Write( p, toPrint );
}
}
// Flush the remaining string. This will be the entire
// string if an entity wasn't found.
TIXMLASSERT( p <= q );
if ( !_processEntities || ( p < q ) ) {
const size_t delta = q - p;
const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta;
Write( p, toPrint );
else {
Write( p );
}
}

View File

@@ -98,12 +98,12 @@ distribution.
/* Versioning, past 1.0.14:
http://semver.org/
*/
static const int TIXML2_MAJOR_VERSION = 6;
static const int TIXML2_MINOR_VERSION = 2;
static const int TIXML2_MAJOR_VERSION = 7;
static const int TIXML2_MINOR_VERSION = 0;
static const int TIXML2_PATCH_VERSION = 0;
#define TINYXML2_MAJOR_VERSION 6
#define TINYXML2_MINOR_VERSION 2
#define TINYXML2_MAJOR_VERSION 7
#define TINYXML2_MINOR_VERSION 0
#define TINYXML2_PATCH_VERSION 0
// A fixed element depth limit is problematic. There needs to be a
@@ -190,7 +190,7 @@ private:
char* _end;
StrPair( const StrPair& other ); // not supported
void operator=( StrPair& other ); // not supported, use TransferTo()
void operator=( const StrPair& other ); // not supported, use TransferTo()
};
@@ -288,7 +288,7 @@ public:
return _mem;
}
T* Mem() {
T* Mem() {
TIXMLASSERT( _mem );
return _mem;
}
@@ -334,7 +334,6 @@ public:
virtual void* Alloc() = 0;
virtual void Free( void* ) = 0;
virtual void SetTracked() = 0;
virtual void Clear() = 0;
};
@@ -347,7 +346,7 @@ class MemPoolT : public MemPool
public:
MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
~MemPoolT() {
Clear();
MemPoolT< ITEM_SIZE >::Clear();
}
void Clear() {
@@ -525,10 +524,8 @@ enum XMLError {
XML_ERROR_FILE_NOT_FOUND,
XML_ERROR_FILE_COULD_NOT_BE_OPENED,
XML_ERROR_FILE_READ_ERROR,
UNUSED_XML_ERROR_ELEMENT_MISMATCH, // remove at next major version
XML_ERROR_PARSING_ELEMENT,
XML_ERROR_PARSING_ATTRIBUTE,
UNUSED_XML_ERROR_IDENTIFYING_TAG, // remove at next major version
XML_ERROR_PARSING_TEXT,
XML_ERROR_PARSING_CDATA,
XML_ERROR_PARSING_COMMENT,
@@ -940,7 +937,7 @@ public:
void* GetUserData() const { return _userData; }
protected:
XMLNode( XMLDocument* );
explicit XMLNode( XMLDocument* );
virtual ~XMLNode();
virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
@@ -1008,7 +1005,7 @@ public:
virtual bool ShallowEqual( const XMLNode* compare ) const;
protected:
XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
virtual ~XMLText() {}
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
@@ -1039,7 +1036,7 @@ public:
virtual bool ShallowEqual( const XMLNode* compare ) const;
protected:
XMLComment( XMLDocument* doc );
explicit XMLComment( XMLDocument* doc );
virtual ~XMLComment();
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
@@ -1078,7 +1075,7 @@ public:
virtual bool ShallowEqual( const XMLNode* compare ) const;
protected:
XMLDeclaration( XMLDocument* doc );
explicit XMLDeclaration( XMLDocument* doc );
virtual ~XMLDeclaration();
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
@@ -1113,7 +1110,7 @@ public:
virtual bool ShallowEqual( const XMLNode* compare ) const;
protected:
XMLUnknown( XMLDocument* doc );
explicit XMLUnknown( XMLDocument* doc );
virtual ~XMLUnknown();
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
@@ -1402,27 +1399,27 @@ public:
QueryAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10
@endverbatim
*/
int QueryAttribute( const char* name, int* value ) const {
XMLError QueryAttribute( const char* name, int* value ) const {
return QueryIntAttribute( name, value );
}
int QueryAttribute( const char* name, unsigned int* value ) const {
XMLError QueryAttribute( const char* name, unsigned int* value ) const {
return QueryUnsignedAttribute( name, value );
}
int QueryAttribute(const char* name, int64_t* value) const {
XMLError QueryAttribute(const char* name, int64_t* value) const {
return QueryInt64Attribute(name, value);
}
int QueryAttribute( const char* name, bool* value ) const {
XMLError QueryAttribute( const char* name, bool* value ) const {
return QueryBoolAttribute( name, value );
}
int QueryAttribute( const char* name, double* value ) const {
XMLError QueryAttribute( const char* name, double* value ) const {
return QueryDoubleAttribute( name, value );
}
int QueryAttribute( const char* name, float* value ) const {
XMLError QueryAttribute( const char* name, float* value ) const {
return QueryFloatAttribute( name, value );
}
@@ -1626,11 +1623,7 @@ private:
XMLElement( const XMLElement& ); // not supported
void operator=( const XMLElement& ); // not supported
XMLAttribute* FindAttribute( const char* name ) {
return const_cast<XMLAttribute*>(const_cast<const XMLElement*>(this)->FindAttribute( name ));
}
XMLAttribute* FindOrCreateAttribute( const char* name );
//void LinkAttribute( XMLAttribute* attrib );
char* ParseAttributes( char* p, int* curLineNumPtr );
static void DeleteAttribute( XMLAttribute* attribute );
XMLAttribute* CreateAttribute();
@@ -1839,7 +1832,7 @@ public:
/// A (trivial) utility function that prints the ErrorStr() to stdout.
void PrintError() const;
/// Return the line where the error occured, or zero if unknown.
/// Return the line where the error occurred, or zero if unknown.
int ErrorLineNum() const
{
return _errorLineNum;
@@ -1907,7 +1900,7 @@ private:
// the stack. Track stack depth, and error out if needed.
class DepthTracker {
public:
DepthTracker(XMLDocument * document) {
explicit DepthTracker(XMLDocument * document) {
this->_document = document;
document->PushDepth();
}
@@ -1996,10 +1989,10 @@ class TINYXML2_LIB XMLHandle
{
public:
/// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
XMLHandle( XMLNode* node ) : _node( node ) {
explicit XMLHandle( XMLNode* node ) : _node( node ) {
}
/// Create a handle from a node.
XMLHandle( XMLNode& node ) : _node( &node ) {
explicit XMLHandle( XMLNode& node ) : _node( &node ) {
}
/// Copy constructor
XMLHandle( const XMLHandle& ref ) : _node( ref._node ) {
@@ -2076,9 +2069,9 @@ private:
class TINYXML2_LIB XMLConstHandle
{
public:
XMLConstHandle( const XMLNode* node ) : _node( node ) {
explicit XMLConstHandle( const XMLNode* node ) : _node( node ) {
}
XMLConstHandle( const XMLNode& node ) : _node( &node ) {
explicit XMLConstHandle( const XMLNode& node ) : _node( &node ) {
}
XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) {
}

View File

@@ -82,8 +82,15 @@ template< class T > bool XMLTest( const char* testString, T expected, T found, b
if ( !echo )
printf (" %s\n", testString);
else
printf (" %s [%d][%d]\n", testString, static_cast<int>(expected), static_cast<int>(found) );
else {
char expectedAsString[64];
XMLUtil::ToStr(expected, expectedAsString, sizeof(expectedAsString));
char foundAsString[64];
XMLUtil::ToStr(found, foundAsString, sizeof(foundAsString));
printf (" %s [%s][%s]\n", testString, expectedAsString, foundAsString );
}
if ( pass )
++gPass;
@@ -569,7 +576,7 @@ int main( int argc, const char ** argv )
XMLTest( "Bad XML", XML_ERROR_PARSING_ATTRIBUTE, doc.ErrorID() );
const char* errorStr = doc.ErrorStr();
XMLTest("Formatted error string",
"Error=XML_ERROR_PARSING_ATTRIBUTE ErrorID=8 (0x8) Line number=3: XMLElement name=wrong",
"Error=XML_ERROR_PARSING_ATTRIBUTE ErrorID=7 (0x7) Line number=3: XMLElement name=wrong",
errorStr);
}
@@ -1176,7 +1183,7 @@ int main( int argc, const char ** argv )
// But be sure there is an error string!
const char* errorStr = doc.ErrorStr();
XMLTest("Error string should be set",
"Error=XML_ERROR_EMPTY_DOCUMENT ErrorID=15 (0xf) Line number=0",
"Error=XML_ERROR_EMPTY_DOCUMENT ErrorID=13 (0xd) Line number=0",
errorStr);
}
@@ -1782,6 +1789,7 @@ int main( int argc, const char ** argv )
XMLTest( "Insertion with removal parse round 4", false, doc.Error() );
subtree = doc.RootElement()->FirstChildElement("one")->FirstChildElement("subtree");
two = doc.RootElement()->FirstChildElement("two");
XMLTest("<two> is the last child at root level", true, two == doc.RootElement()->LastChildElement());
doc.RootElement()->InsertEndChild(subtree);
XMLPrinter printer4(0, true);
acceptResult = doc.Accept(&printer4);
@@ -1967,7 +1975,7 @@ int main( int argc, const char ** argv )
{
// No matter - before or after successfully parsing a text -
// calling XMLDocument::Value() used to cause an assert in debug.
// Null must be retured.
// Null must be returned.
const char* validXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
"<first />"
"<second />";
@@ -1995,6 +2003,17 @@ int main( int argc, const char ** argv )
}
}
{
const char* html("<!DOCTYPE html><html><body><p>test</p><p><br/></p></body></html>");
XMLDocument doc(false);
doc.Parse(html);
XMLPrinter printer(0, true);
doc.Print(&printer);
XMLTest(html, html, printer.CStr());
}
{
// Evil memory leaks.
// If an XMLElement (etc) is allocated via NewElement() (etc.)
@@ -2039,6 +2058,18 @@ int main( int argc, const char ** argv )
XMLTest("Stack overflow prevented.", XML_ELEMENT_DEPTH_EXCEEDED, doc.ErrorID());
}
}
{
const char* TESTS[] = {
"./resources/xmltest-5662204197076992.xml", // Security-level performance issue.
0
};
for (int i = 0; TESTS[i]; ++i) {
XMLDocument doc;
doc.LoadFile(TESTS[i]);
// Need only not crash / lock up.
XMLTest("Fuzz attack prevented.", true, true);
}
}
{
// Crashing reported via email.
const char* xml =