From 2d6638008c2aeba6015d45160e52d78d92daf57d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 26 Dec 2013 16:04:58 +0100 Subject: cmTarget: Use strtol for numeric parsing. On Windows apparently sscanf can not handle hex numbers. Test that numeric comparison works with hex numbers. --- Source/cmTarget.cxx | 14 ++++++++++---- Tests/CompatibleInterface/CMakeLists.txt | 10 +++++++++- Tests/CompatibleInterface/main.cpp | 4 +++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index ead48b9..472f87d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -24,6 +24,7 @@ #include #include // required for atof #include +#include const char* cmTarget::GetTargetTypeName(TargetType targetType) { @@ -4274,6 +4275,7 @@ std::pair consistentNumberProperty(const char *lhs, const char *rhs, CompatibleType t) { + char *pEnd; #if defined(_MSC_VER) static const char* const null_ptr = 0; @@ -4281,10 +4283,14 @@ std::pair consistentNumberProperty(const char *lhs, # define null_ptr 0 #endif - double lnum; - double rnum; - if(sscanf(lhs, "%lg", &lnum) != 1 || - sscanf(rhs, "%lg", &rnum) != 1) + long lnum = strtol(lhs, &pEnd, 0); + if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) + { + return std::pair(false, null_ptr); + } + + long rnum = strtol(rhs, &pEnd, 0); + if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE) { return std::pair(false, null_ptr); } diff --git a/Tests/CompatibleInterface/CMakeLists.txt b/Tests/CompatibleInterface/CMakeLists.txt index 5e64d2a..47e974a 100644 --- a/Tests/CompatibleInterface/CMakeLists.txt +++ b/Tests/CompatibleInterface/CMakeLists.txt @@ -24,6 +24,8 @@ set_property(TARGET iface1 APPEND PROPERTY COMPATIBLE_INTERFACE_NUMBER_MIN NUMBER_MIN_PROP1 NUMBER_MIN_PROP2 + NUMBER_MIN_PROP3 + NUMBER_MIN_PROP4 ) set_property(TARGET iface1 APPEND PROPERTY COMPATIBLE_INTERFACE_NUMBER_MAX @@ -34,7 +36,7 @@ set_property(TARGET iface1 APPEND PROPERTY set(CMAKE_DEBUG_TARGET_PROPERTIES BOOL_PROP1 BOOL_PROP2 BOOL_PROP3 BOOL_PROP4 STRING_PROP1 STRING_PROP2 STRING_PROP3 - NUMBER_MIN_PROP1 NUMBER_MIN_PROP2 + NUMBER_MIN_PROP1 NUMBER_MIN_PROP2 NUMBER_MIN_PROP3 NUMBER_MIN_PROP4 NUMBER_MAX_PROP1 NUMBER_MAX_PROP2 ) @@ -44,6 +46,8 @@ set_property(TARGET iface1 PROPERTY INTERFACE_STRING_PROP1 prop1) set_property(TARGET iface1 PROPERTY INTERFACE_STRING_PROP2 prop2) set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP1 100) set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP2 200) +set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP3 0x10) +set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP4 0x10) set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MAX_PROP1 100) set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MAX_PROP2 200) @@ -56,6 +60,8 @@ set_property(TARGET CompatibleInterface PROPERTY STRING_PROP2 prop2) set_property(TARGET CompatibleInterface PROPERTY STRING_PROP3 prop3) set_property(TARGET CompatibleInterface PROPERTY NUMBER_MIN_PROP1 50) set_property(TARGET CompatibleInterface PROPERTY NUMBER_MIN_PROP2 250) +set_property(TARGET CompatibleInterface PROPERTY NUMBER_MIN_PROP3 0xA) +set_property(TARGET CompatibleInterface PROPERTY NUMBER_MIN_PROP4 0x1A) set_property(TARGET CompatibleInterface PROPERTY NUMBER_MAX_PROP1 50) set_property(TARGET CompatibleInterface PROPERTY NUMBER_MAX_PROP2 250) @@ -69,6 +75,8 @@ target_compile_definitions(CompatibleInterface $<$,prop3>:STRING_PROP3> $<$,50>:NUMBER_MIN_PROP1=50> $<$,200>:NUMBER_MIN_PROP2=200> + $<$,0xA>:NUMBER_MIN_PROP3=0xA> + $<$,0x10>:NUMBER_MIN_PROP4=0x10> $<$,100>:NUMBER_MAX_PROP1=100> $<$,250>:NUMBER_MAX_PROP2=250> ) diff --git a/Tests/CompatibleInterface/main.cpp b/Tests/CompatibleInterface/main.cpp index fa299e9..e23625a 100644 --- a/Tests/CompatibleInterface/main.cpp +++ b/Tests/CompatibleInterface/main.cpp @@ -33,7 +33,9 @@ enum { NumericMaxTest1 = sizeof(CMakeStaticAssert), NumericMaxTest2 = sizeof(CMakeStaticAssert), NumericMinTest1 = sizeof(CMakeStaticAssert), - NumericMinTest2 = sizeof(CMakeStaticAssert) + NumericMinTest2 = sizeof(CMakeStaticAssert), + NumericMinTest3 = sizeof(CMakeStaticAssert), + NumericMinTest4 = sizeof(CMakeStaticAssert) }; #include "iface2.h" -- cgit v0.12