Browse Source

Replace some uses of sprintf with std::to_string

jrp2014 7 years ago
parent
commit
acda926a04
2 changed files with 18 additions and 19 deletions
  1. 9 9
      Source/cmCacheManager.cxx
  2. 9 10
      Source/cmStateSnapshot.cxx

+ 9 - 9
Source/cmCacheManager.cxx

@@ -8,6 +8,7 @@
 #include <sstream>
 #include <stdio.h>
 #include <string.h>
+#include <string>
 
 #include "cmGeneratedFileStream.h"
 #include "cmMessenger.h"
@@ -243,19 +244,18 @@ bool cmCacheManager::SaveCache(const std::string& path, cmMessenger* messenger)
   }
   // before writing the cache, update the version numbers
   // to the
-  char temp[1024];
-  sprintf(temp, "%d", cmVersion::GetMinorVersion());
-  this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", temp,
-                      "Minor version of cmake used to create the "
+  this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION",
+                      std::to_string(cmVersion::GetMajorVersion()).c_str(),
+                      "Major version of cmake used to create the "
                       "current loaded cache",
                       cmStateEnums::INTERNAL);
-  sprintf(temp, "%d", cmVersion::GetMajorVersion());
-  this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", temp,
-                      "Major version of cmake used to create the "
+  this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION",
+                      std::to_string(cmVersion::GetMinorVersion()).c_str(),
+                      "Minor version of cmake used to create the "
                       "current loaded cache",
                       cmStateEnums::INTERNAL);
-  sprintf(temp, "%d", cmVersion::GetPatchVersion());
-  this->AddCacheEntry("CMAKE_CACHE_PATCH_VERSION", temp,
+  this->AddCacheEntry("CMAKE_CACHE_PATCH_VERSION",
+                      std::to_string(cmVersion::GetPatchVersion()).c_str(),
                       "Patch version of cmake used to create the "
                       "current loaded cache",
                       cmStateEnums::INTERNAL);

+ 9 - 10
Source/cmStateSnapshot.cxx

@@ -6,7 +6,7 @@
 #include <algorithm>
 #include <assert.h>
 #include <iterator>
-#include <stdio.h>
+#include <string>
 
 #include "cmAlgorithms.h"
 #include "cmDefinitions.h"
@@ -328,15 +328,14 @@ void cmStateSnapshot::SetDefaultDefinitions()
   this->SetDefinition("CMAKE_HOST_SOLARIS", "1");
 #endif
 
-  char temp[1024];
-  sprintf(temp, "%d", cmVersion::GetMinorVersion());
-  this->SetDefinition("CMAKE_MINOR_VERSION", temp);
-  sprintf(temp, "%d", cmVersion::GetMajorVersion());
-  this->SetDefinition("CMAKE_MAJOR_VERSION", temp);
-  sprintf(temp, "%d", cmVersion::GetPatchVersion());
-  this->SetDefinition("CMAKE_PATCH_VERSION", temp);
-  sprintf(temp, "%d", cmVersion::GetTweakVersion());
-  this->SetDefinition("CMAKE_TWEAK_VERSION", temp);
+  this->SetDefinition("CMAKE_MAJOR_VERSION",
+                      std::to_string(cmVersion::GetMajorVersion()));
+  this->SetDefinition("CMAKE_MINOR_VERSION",
+                      std::to_string(cmVersion::GetMinorVersion()));
+  this->SetDefinition("CMAKE_PATCH_VERSION",
+                      std::to_string(cmVersion::GetPatchVersion()));
+  this->SetDefinition("CMAKE_TWEAK_VERSION",
+                      std::to_string(cmVersion::GetTweakVersion()));
   this->SetDefinition("CMAKE_VERSION", cmVersion::GetCMakeVersion());
 
   this->SetDefinition("CMAKE_FILES_DIRECTORY",