浏览代码

cmLocalGenerator: Remove AppendFlags 'const char*' overload

Update call sites to ensure the `std::string` argument can be
constructed safely.
Brad King 6 年之前
父节点
当前提交
5acf0de1fe

+ 1 - 1
Source/cmCommonTargetGenerator.cxx

@@ -90,7 +90,7 @@ void cmCommonTargetGenerator::AppendFortranFormatFlags(
   }
   if (var) {
     this->LocalCommonGenerator->AppendFlags(
-      flags, this->Makefile->GetDefinition(var));
+      flags, this->Makefile->GetSafeDefinition(var));
   }
 }
 

+ 2 - 4
Source/cmLocalCommonGenerator.cxx

@@ -35,10 +35,8 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags(
   std::string flags;
 
   // Enable module output if necessary.
-  if (const char* modout_flag =
-        this->Makefile->GetDefinition("CMAKE_Fortran_MODOUT_FLAG")) {
-    this->AppendFlags(flags, modout_flag);
-  }
+  this->AppendFlags(
+    flags, this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODOUT_FLAG"));
 
   // Add a module output directory flag if necessary.
   std::string mod_dir =

+ 5 - 13
Source/cmLocalGenerator.cxx

@@ -1125,10 +1125,10 @@ void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
       this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name));
     }
   }
-  this->AppendFlags(flags, target->GetProperty("STATIC_LIBRARY_FLAGS"));
+  this->AppendFlags(flags, target->GetSafeProperty("STATIC_LIBRARY_FLAGS"));
   if (!config.empty()) {
     std::string name = "STATIC_LIBRARY_FLAGS_" + config;
-    this->AppendFlags(flags, target->GetProperty(name));
+    this->AppendFlags(flags, target->GetSafeProperty(name));
   }
 
   std::vector<std::string> options;
@@ -1744,7 +1744,7 @@ void cmLocalGenerator::AddSharedFlags(std::string& flags,
   // Add flags for dealing with shared libraries for this language.
   if (shared) {
     this->AppendFlags(flags,
-                      this->Makefile->GetDefinition(
+                      this->Makefile->GetSafeDefinition(
                         cmStrCat("CMAKE_SHARED_LIBRARY_", lang, "_FLAGS")));
   }
 }
@@ -2090,12 +2090,12 @@ void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
 {
   // Add the flags from the variable itself.
   std::string flagsVar = var;
-  this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
+  this->AppendFlags(flags, this->Makefile->GetSafeDefinition(flagsVar));
   // Add the flags from the build-type specific variable.
   if (!config.empty()) {
     flagsVar += "_";
     flagsVar += cmSystemTools::UpperCase(config);
-    this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
+    this->AppendFlags(flags, this->Makefile->GetSafeDefinition(flagsVar));
   }
 }
 
@@ -2110,14 +2110,6 @@ void cmLocalGenerator::AppendFlags(std::string& flags,
   }
 }
 
-void cmLocalGenerator::AppendFlags(std::string& flags,
-                                   const char* newFlags) const
-{
-  if (newFlags && *newFlags) {
-    this->AppendFlags(flags, std::string(newFlags));
-  }
-}
-
 void cmLocalGenerator::AppendFlagEscape(std::string& flags,
                                         const std::string& rawFlag) const
 {

+ 0 - 1
Source/cmLocalGenerator.h

@@ -121,7 +121,6 @@ public:
   //! Append flags to a string.
   virtual void AppendFlags(std::string& flags,
                            const std::string& newFlags) const;
-  virtual void AppendFlags(std::string& flags, const char* newFlags) const;
   virtual void AppendFlagEscape(std::string& flags,
                                 const std::string& rawFlag) const;
   void AddPchDependencies(cmGeneratorTarget* target,

+ 0 - 6
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -831,12 +831,6 @@ void cmLocalUnixMakefileGenerator3::AppendFlags(
   this->cmLocalGenerator::AppendFlags(flags, newFlags);
 }
 
-void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags,
-                                                const char* newFlags) const
-{
-  this->cmLocalGenerator::AppendFlags(flags, newFlags);
-}
-
 void cmLocalUnixMakefileGenerator3::AppendRuleDepend(
   std::vector<std::string>& depends, const char* ruleFileName)
 {

+ 0 - 1
Source/cmLocalUnixMakefileGenerator3.h

@@ -90,7 +90,6 @@ public:
   // append flags to a string
   void AppendFlags(std::string& flags,
                    const std::string& newFlags) const override;
-  void AppendFlags(std::string& flags, const char* newFlags) const override;
 
   // append an echo command
   enum EchoColor

+ 5 - 4
Source/cmMakefileExecutableTargetGenerator.cxx

@@ -135,7 +135,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
     std::string export_flag_var =
       cmStrCat("CMAKE_EXE_EXPORTS_", linkLanguage, "_FLAG");
     this->LocalGenerator->AppendFlags(
-      linkFlags, this->Makefile->GetDefinition(export_flag_var));
+      linkFlags, this->Makefile->GetSafeDefinition(export_flag_var));
   }
 
   this->LocalGenerator->AppendFlags(linkFlags,
@@ -387,10 +387,11 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
 
   if (this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE")) {
     this->LocalGenerator->AppendFlags(
-      linkFlags, this->Makefile->GetDefinition("CMAKE_CREATE_WIN32_EXE"));
+      linkFlags, this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE"));
   } else {
     this->LocalGenerator->AppendFlags(
-      linkFlags, this->Makefile->GetDefinition("CMAKE_CREATE_CONSOLE_EXE"));
+      linkFlags,
+      this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE"));
   }
 
   // Add symbol export flags if necessary.
@@ -398,7 +399,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
     std::string export_flag_var =
       cmStrCat("CMAKE_EXE_EXPORTS_", linkLanguage, "_FLAG");
     this->LocalGenerator->AppendFlags(
-      linkFlags, this->Makefile->GetDefinition(export_flag_var));
+      linkFlags, this->Makefile->GetSafeDefinition(export_flag_var));
   }
 
   this->LocalGenerator->AppendFlags(linkFlags,

+ 2 - 2
Source/cmMakefileTargetGenerator.cxx

@@ -89,12 +89,12 @@ void cmMakefileTargetGenerator::GetTargetLinkFlags(
   std::string& flags, const std::string& linkLanguage)
 {
   this->LocalGenerator->AppendFlags(
-    flags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
+    flags, this->GeneratorTarget->GetSafeProperty("LINK_FLAGS"));
 
   std::string linkFlagsConfig =
     cmStrCat("LINK_FLAGS_", cmSystemTools::UpperCase(this->ConfigName));
   this->LocalGenerator->AppendFlags(
-    flags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
+    flags, this->GeneratorTarget->GetSafeProperty(linkFlagsConfig));
 
   std::vector<std::string> opts;
   this->GeneratorTarget->GetLinkOptions(opts, this->ConfigName, linkLanguage);