mirror of
https://github.com/leethomason/tinyxml2.git
synced 2026-07-25 21:23:00 +04:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ce9f9a3a7 | |||
| 682fda289f | |||
| e6a464942f | |||
| 98137e6936 | |||
| aba13c50bf | |||
| e48a1310fe | |||
| fc99428a82 |
+58
-13
@@ -24,7 +24,7 @@ distribution.
|
||||
#include "tinyxml2.h"
|
||||
|
||||
#include <new> // yes, this one new style header, is in the Android SDK.
|
||||
#if defined(ANDROID_NDK)
|
||||
#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__) || defined(__CC_ARM)
|
||||
# include <stddef.h>
|
||||
# include <stdarg.h>
|
||||
#else
|
||||
@@ -40,7 +40,9 @@ distribution.
|
||||
# define __has_cpp_attribute(x) 0
|
||||
#endif
|
||||
|
||||
#if (__cplusplus >= 201703L && __has_cpp_attribute(fallthrough))
|
||||
#if defined(_MSC_VER)
|
||||
# define TIXML_FALLTHROUGH (void(0))
|
||||
#elif (__cplusplus >= 201703L && __has_cpp_attribute(fallthrough))
|
||||
# define TIXML_FALLTHROUGH [[fallthrough]]
|
||||
#elif __has_cpp_attribute(clang::fallthrough)
|
||||
# define TIXML_FALLTHROUGH [[clang::fallthrough]]
|
||||
@@ -51,8 +53,15 @@ distribution.
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
// Microsoft Visual Studio, version 2005 and higher.
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
|
||||
// Microsoft Visual Studio, version 2005 and higher. Not WinCE.
|
||||
/*int _snprintf_s(
|
||||
char *buffer,
|
||||
size_t sizeOfBuffer,
|
||||
size_t count,
|
||||
const char *format [,
|
||||
argument] ...
|
||||
);*/
|
||||
static inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
|
||||
{
|
||||
va_list va;
|
||||
@@ -71,11 +80,33 @@ distribution.
|
||||
#define TIXML_VSCPRINTF _vscprintf
|
||||
#define TIXML_SSCANF sscanf_s
|
||||
#elif defined _MSC_VER
|
||||
// Microsoft Visual Studio 2003 and earlier.
|
||||
// Microsoft Visual Studio 2003 and earlier or WinCE
|
||||
#define TIXML_SNPRINTF _snprintf
|
||||
#define TIXML_VSNPRINTF _vsnprintf
|
||||
#define TIXML_SSCANF sscanf
|
||||
#define TIXML_VSCPRINTF _vscprintf
|
||||
#if (_MSC_VER < 1400 ) && (!defined WINCE)
|
||||
// Microsoft Visual Studio 2003 and not WinCE.
|
||||
#define TIXML_VSCPRINTF _vscprintf // VS2003's C runtime has this, but VC6 C runtime or WinCE SDK doesn't have.
|
||||
#else
|
||||
// Microsoft Visual Studio 2003 and earlier or WinCE.
|
||||
static inline int TIXML_VSCPRINTF( const char* format, va_list va )
|
||||
{
|
||||
int len = 512;
|
||||
for (;;) {
|
||||
len = len*2;
|
||||
char* str = new char[len]();
|
||||
const int required = _vsnprintf(str, len, format, va);
|
||||
delete[] str;
|
||||
if ( required != -1 ) {
|
||||
TIXMLASSERT( required >= 0 );
|
||||
len = required;
|
||||
break;
|
||||
}
|
||||
}
|
||||
TIXMLASSERT( len >= 0 );
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
// GCC version 3 and higher
|
||||
//#warning( "Using sn* functions." )
|
||||
@@ -83,6 +114,9 @@ distribution.
|
||||
#define TIXML_VSNPRINTF vsnprintf
|
||||
static inline int TIXML_VSCPRINTF( const char* format, va_list va )
|
||||
{
|
||||
if (!format) {
|
||||
return 0;
|
||||
}
|
||||
int len = vsnprintf( 0, 0, format, va );
|
||||
TIXMLASSERT( len >= 0 );
|
||||
return len;
|
||||
@@ -90,7 +124,7 @@ distribution.
|
||||
#define TIXML_SSCANF sscanf
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_WIN64)
|
||||
#define TIXML_FSEEK _fseeki64
|
||||
#define TIXML_FTELL _ftelli64
|
||||
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)
|
||||
@@ -800,7 +834,17 @@ XMLNode::XMLNode( XMLDocument* doc ) :
|
||||
|
||||
XMLNode::~XMLNode()
|
||||
{
|
||||
DeleteChildren();
|
||||
// Fast path: this node is dying, so maintaining _firstChild/_lastChild and
|
||||
// sibling _prev/_next links is unnecessary. Only _parent must be zeroed to
|
||||
// satisfy the MarkInUse assertion inside DeleteNode.
|
||||
XMLNode *currentChild = _firstChild;
|
||||
while (currentChild != NULL) {
|
||||
XMLNode *next = currentChild->_next;
|
||||
currentChild->_parent = 0;
|
||||
DeleteNode(currentChild);
|
||||
currentChild = next;
|
||||
}
|
||||
|
||||
if ( _parent ) {
|
||||
_parent->Unlink( this );
|
||||
}
|
||||
@@ -2226,7 +2270,7 @@ void XMLDocument::Clear()
|
||||
delete [] _charBuffer;
|
||||
_charBuffer = 0;
|
||||
_parsingDepth = 0;
|
||||
|
||||
|
||||
#if 0
|
||||
_textPool.Trace( "text" );
|
||||
_elementPool.Trace( "element" );
|
||||
@@ -2301,7 +2345,7 @@ static FILE* callfopen( const char* filepath, const char* mode )
|
||||
{
|
||||
TIXMLASSERT( filepath );
|
||||
TIXMLASSERT( mode );
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
|
||||
FILE* fp = 0;
|
||||
const errno_t err = fopen_s( &fp, filepath, mode );
|
||||
if ( err ) {
|
||||
@@ -2313,9 +2357,10 @@ static FILE* callfopen( const char* filepath, const char* mode )
|
||||
return fp;
|
||||
}
|
||||
|
||||
void XMLDocument::DeleteNode( XMLNode* node ) {
|
||||
TIXMLASSERT( node );
|
||||
TIXMLASSERT(node->_document == this );
|
||||
void XMLDocument::DeleteNode( XMLNode* node ) {
|
||||
if(node == 0) {
|
||||
return; // check for null pointer
|
||||
}
|
||||
if (node->_parent) {
|
||||
node->_parent->DeleteChild( node );
|
||||
}
|
||||
|
||||
+4
-1
@@ -24,12 +24,15 @@ distribution.
|
||||
#ifndef TINYXML2_INCLUDED
|
||||
#define TINYXML2_INCLUDED
|
||||
|
||||
#if defined(ANDROID_NDK)
|
||||
#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
|
||||
# include <ctype.h>
|
||||
# include <limits.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# if defined(__PS3__)
|
||||
# include <stddef.h>
|
||||
# endif
|
||||
#else
|
||||
# include <cctype>
|
||||
# include <climits>
|
||||
|
||||
+7
-1
@@ -2025,7 +2025,13 @@ int main( int argc, const char ** argv )
|
||||
XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", true, 0 == doc.RootElement()->FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
//Check the robustness of the DeleteNode function in handling null pointers.
|
||||
{
|
||||
XMLDocument doc;
|
||||
doc.DeleteNode(nullptr);
|
||||
XMLTest("DeleteNode with null pointer", true, doc.Error() == XML_SUCCESS);
|
||||
}
|
||||
|
||||
// Check sample xml can be parsed with pedantic mode
|
||||
{
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
|
||||
Reference in New Issue
Block a user