Merge pull request #732 from orbitcowboy/master
Improved const correctness of local variables. There are no functiona…
This commit is contained in:
24
tinyxml2.cpp
24
tinyxml2.cpp
@@ -45,14 +45,14 @@ distribution.
|
|||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start( va, format );
|
va_start( va, format );
|
||||||
int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
|
const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
|
||||||
va_end( va );
|
va_end( va );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int TIXML_VSNPRINTF( char* buffer, size_t size, const char* format, va_list va )
|
static inline int TIXML_VSNPRINTF( char* buffer, size_t size, const char* format, va_list va )
|
||||||
{
|
{
|
||||||
int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
|
const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags, int* curLin
|
|||||||
TIXMLASSERT(curLineNumPtr);
|
TIXMLASSERT(curLineNumPtr);
|
||||||
|
|
||||||
char* start = p;
|
char* start = p;
|
||||||
char endChar = *endTag;
|
const char endChar = *endTag;
|
||||||
size_t length = strlen( endTag );
|
size_t length = strlen( endTag );
|
||||||
|
|
||||||
// Inner loop of text parsing.
|
// Inner loop of text parsing.
|
||||||
@@ -310,7 +310,7 @@ const char* StrPair::GetStr()
|
|||||||
const int buflen = 10;
|
const int buflen = 10;
|
||||||
char buf[buflen] = { 0 };
|
char buf[buflen] = { 0 };
|
||||||
int len = 0;
|
int len = 0;
|
||||||
char* adjusted = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
|
const char* adjusted = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
|
||||||
if ( adjusted == 0 ) {
|
if ( adjusted == 0 ) {
|
||||||
*q = *p;
|
*q = *p;
|
||||||
++p;
|
++p;
|
||||||
@@ -1017,7 +1017,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int initialLineNum = node->_parseLineNum;
|
const int initialLineNum = node->_parseLineNum;
|
||||||
|
|
||||||
StrPair endTag;
|
StrPair endTag;
|
||||||
p = node->ParseDeep( p, &endTag, curLineNumPtr );
|
p = node->ParseDeep( p, &endTag, curLineNumPtr );
|
||||||
@@ -1029,7 +1029,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLDeclaration* decl = node->ToDeclaration();
|
const XMLDeclaration* const decl = node->ToDeclaration();
|
||||||
if ( decl ) {
|
if ( decl ) {
|
||||||
// Declarations are only allowed at document level
|
// Declarations are only allowed at document level
|
||||||
//
|
//
|
||||||
@@ -1038,7 +1038,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
|||||||
//
|
//
|
||||||
// Optimized due to a security test case. If the first node is
|
// Optimized due to a security test case. If the first node is
|
||||||
// a declaration, and the last node is a declaration, then only
|
// a declaration, and the last node is a declaration, then only
|
||||||
// declarations have so far been addded.
|
// declarations have so far been added.
|
||||||
bool wellLocated = false;
|
bool wellLocated = false;
|
||||||
|
|
||||||
if (ToDocument()) {
|
if (ToDocument()) {
|
||||||
@@ -1373,7 +1373,7 @@ char* XMLAttribute::ParseDeep( char* p, bool processEntities, int* curLineNumPtr
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char endTag[2] = { *p, 0 };
|
const char endTag[2] = { *p, 0 };
|
||||||
++p; // move past opening quote
|
++p; // move past opening quote
|
||||||
|
|
||||||
p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES, curLineNumPtr );
|
p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES, curLineNumPtr );
|
||||||
@@ -1830,7 +1830,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr )
|
|||||||
TIXMLASSERT( attrib );
|
TIXMLASSERT( attrib );
|
||||||
attrib->_parseLineNum = _document->_parseCurLineNum;
|
attrib->_parseLineNum = _document->_parseCurLineNum;
|
||||||
|
|
||||||
int attrLineNum = attrib->_parseLineNum;
|
const int attrLineNum = attrib->_parseLineNum;
|
||||||
|
|
||||||
p = attrib->ParseDeep( p, _document->ProcessEntities(), curLineNumPtr );
|
p = attrib->ParseDeep( p, _document->ProcessEntities(), curLineNumPtr );
|
||||||
if ( !p || Attribute( attrib->Name() ) ) {
|
if ( !p || Attribute( attrib->Name() ) ) {
|
||||||
@@ -2136,7 +2136,7 @@ static FILE* callfopen( const char* filepath, const char* mode )
|
|||||||
TIXMLASSERT( mode );
|
TIXMLASSERT( mode );
|
||||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
|
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
|
||||||
FILE* fp = 0;
|
FILE* fp = 0;
|
||||||
errno_t err = fopen_s( &fp, filepath, mode );
|
const errno_t err = fopen_s( &fp, filepath, mode );
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -2239,7 +2239,7 @@ XMLError XMLDocument::LoadFile( FILE* fp )
|
|||||||
const size_t size = filelength;
|
const size_t size = filelength;
|
||||||
TIXMLASSERT( _charBuffer == 0 );
|
TIXMLASSERT( _charBuffer == 0 );
|
||||||
_charBuffer = new char[size+1];
|
_charBuffer = new char[size+1];
|
||||||
size_t read = fread( _charBuffer, 1, size, fp );
|
const size_t read = fread( _charBuffer, 1, size, fp );
|
||||||
if ( read != size ) {
|
if ( read != size ) {
|
||||||
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
|
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
|
||||||
return _errorID;
|
return _errorID;
|
||||||
@@ -2332,7 +2332,7 @@ void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ...
|
|||||||
_errorLineNum = lineNum;
|
_errorLineNum = lineNum;
|
||||||
_errorStr.Reset();
|
_errorStr.Reset();
|
||||||
|
|
||||||
size_t BUFFER_SIZE = 1000;
|
const size_t BUFFER_SIZE = 1000;
|
||||||
char* buffer = new char[BUFFER_SIZE];
|
char* buffer = new char[BUFFER_SIZE];
|
||||||
|
|
||||||
TIXMLASSERT(sizeof(error) <= sizeof(int));
|
TIXMLASSERT(sizeof(error) <= sizeof(int));
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ private:
|
|||||||
TIXMLASSERT( cap > 0 );
|
TIXMLASSERT( cap > 0 );
|
||||||
if ( cap > _allocated ) {
|
if ( cap > _allocated ) {
|
||||||
TIXMLASSERT( cap <= INT_MAX / 2 );
|
TIXMLASSERT( cap <= INT_MAX / 2 );
|
||||||
int newAllocated = cap * 2;
|
const int newAllocated = cap * 2;
|
||||||
T* newMem = new T[newAllocated];
|
T* newMem = new T[newAllocated];
|
||||||
TIXMLASSERT( newAllocated >= _size );
|
TIXMLASSERT( newAllocated >= _size );
|
||||||
memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
|
memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
|
||||||
|
|||||||
Reference in New Issue
Block a user