Merge pull request #841 from pazner/master
Fix errors/warnings with hexadecimal format string in sscanf
This commit is contained in:
32
tinyxml2.cpp
32
tinyxml2.cpp
@@ -610,8 +610,17 @@ void XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize )
|
|||||||
|
|
||||||
bool XMLUtil::ToInt(const char* str, int* value)
|
bool XMLUtil::ToInt(const char* str, int* value)
|
||||||
{
|
{
|
||||||
if (TIXML_SSCANF(str, IsPrefixHex(str) ? "%x" : "%d", value) == 1) {
|
if (IsPrefixHex(str)) {
|
||||||
return true;
|
unsigned v;
|
||||||
|
if (TIXML_SSCANF(str, "%x", &v) == 1) {
|
||||||
|
*value = static_cast<int>(v);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (TIXML_SSCANF(str, "%d", value) == 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -670,11 +679,20 @@ bool XMLUtil::ToDouble( const char* str, double* value )
|
|||||||
|
|
||||||
bool XMLUtil::ToInt64(const char* str, int64_t* value)
|
bool XMLUtil::ToInt64(const char* str, int64_t* value)
|
||||||
{
|
{
|
||||||
long long v = 0; // horrible syntax trick to make the compiler happy about %lld
|
if (IsPrefixHex(str)) {
|
||||||
if (TIXML_SSCANF(str, IsPrefixHex(str) ? "%llx" : "%lld", &v) == 1) {
|
unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llx
|
||||||
*value = static_cast<int64_t>(v);
|
if (TIXML_SSCANF(str, "%llx", &v) == 1) {
|
||||||
return true;
|
*value = static_cast<int64_t>(v);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
long long v = 0; // horrible syntax trick to make the compiler happy about %lld
|
||||||
|
if (TIXML_SSCANF(str, "%lld", &v) == 1) {
|
||||||
|
*value = static_cast<int64_t>(v);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user