mirror of
https://github.com/AxioDL/tinyxml2.git
synced 2025-05-14 19:31:23 +00:00
Make code more defensive
* initialize out-parameter for cases the callee fails to * add assert for length being within range * replace post-assert with pre-assert Also replace the loop with an equivalent memcpy() call
This commit is contained in:
parent
dc50a31758
commit
63f3de1a3c
13
tinyxml2.cpp
13
tinyxml2.cpp
@ -216,13 +216,14 @@ const char* StrPair::GetStr()
|
|||||||
// 中 or 中
|
// 中 or 中
|
||||||
|
|
||||||
if ( *(p+1) == '#' ) {
|
if ( *(p+1) == '#' ) {
|
||||||
char buf[10] = { 0 };
|
const int buflen = 10;
|
||||||
int len;
|
char buf[buflen] = { 0 };
|
||||||
|
int len = 0;
|
||||||
p = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
|
p = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
|
||||||
for( int i=0; i<len; ++i ) {
|
TIXMLASSERT( 0 <= len && len <= buflen );
|
||||||
*q++ = buf[i];
|
TIXMLASSERT( q + len <= p );
|
||||||
}
|
memcpy( q, buf, len );
|
||||||
TIXMLASSERT( q <= p );
|
q += len;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int i=0;
|
int i=0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user