Brad King wrote:
> On 11/25/2014 06:24 PM, Ruslan Baratov wrote:
> > updated
> 
> Thanks.  I squashed the commits since the addition of the files
> cannot be tested independently, made minor tweaks, and merged
> to 'next' for testing:
> 
>  cmSystemTools: Add StringToInt helper
>  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5121f118

Since I hate *scanf() with passion, how about this:

diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 4c08e07..9852dd6 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -2927,7 +2927,7 @@ std::vector<std::string> cmSystemTools::tokenize(const 
std::string& str,
 //----------------------------------------------------------------------------
 bool cmSystemTools::StringToInt(const char* str, int* value)
 {
-  char unused;
-  const int result = sscanf(str, "%d%c", value, &unused);
-  return (result == 1);
+  char *endp;
+  *value = static_cast<int>(strtol(str, &endp, 10));
+  return (*endp == '\0') && (endp != str);
 }

Eike
-- 

Attachment: signature.asc
Description: This is a digitally signed message part.

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to