Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/leethomason/tinyxml2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Pazner <will.e.p@gmail.com>2020-11-20 07:50:36 +0300
committerWill Pazner <will.e.p@gmail.com>2020-11-20 07:50:36 +0300
commitd3a82c5e45566cbce3024ad34094cc1e2d45544e (patch)
treeb4e44b9cf96bc12bccbd504c197422f8aedafc87
parent1aeb57d26bc303d5cfa1a9ff2a331df7ba278656 (diff)
Fix format string errors in sscanf
-rwxr-xr-xtinyxml2.cpp32
1 files changed, 25 insertions, 7 deletions
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index 1bacbe1..13b5ce0 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -610,8 +610,17 @@ void XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize )
bool XMLUtil::ToInt(const char* str, int* value)
{
- if (TIXML_SSCANF(str, IsPrefixHex(str) ? "%x" : "%d", value) == 1) {
- return true;
+ if (IsPrefixHex(str)) {
+ 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;
}
@@ -670,11 +679,20 @@ bool XMLUtil::ToDouble( const char* str, double* 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 (TIXML_SSCANF(str, IsPrefixHex(str) ? "%llx" : "%lld", &v) == 1) {
- *value = static_cast<int64_t>(v);
- return true;
- }
+ if (IsPrefixHex(str)) {
+ unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llx
+ if (TIXML_SSCANF(str, "%llx", &v) == 1) {
+ *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;
}