From a46fdda46422c4d41afc44a5df02104acfee78ba Mon Sep 17 00:00:00 2001 From: vvs31415 Date: Sat, 5 Sep 2020 14:09:04 -0400 Subject: cmGeneratorTarget: Avoid missing nullptr check Revise logic in `ComputeOutputDir` that was previously missing a check for nullptr before constructing a `std::string`. Fixes: #21165 --- Source/cmGeneratorTarget.cxx | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index f8568b3..1bb069f 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -6472,21 +6472,16 @@ bool cmGeneratorTarget::ComputeOutputDir(const std::string& config, // Look for a target property defining the target output directory // based on the target type. std::string targetTypeName = this->GetOutputTargetType(artifact); - const char* propertyName = nullptr; - std::string propertyNameStr = targetTypeName; - if (!propertyNameStr.empty()) { - propertyNameStr += "_OUTPUT_DIRECTORY"; - propertyName = propertyNameStr.c_str(); + std::string propertyName; + if (!targetTypeName.empty()) { + propertyName = cmStrCat(targetTypeName, "_OUTPUT_DIRECTORY"); } // Check for a per-configuration output directory target property. std::string configUpper = cmSystemTools::UpperCase(conf); - const char* configProp = nullptr; - std::string configPropStr = targetTypeName; - if (!configPropStr.empty()) { - configPropStr += "_OUTPUT_DIRECTORY_"; - configPropStr += configUpper; - configProp = configPropStr.c_str(); + std::string configProp; + if (!targetTypeName.empty()) { + configProp = cmStrCat(targetTypeName, "_OUTPUT_DIRECTORY_", configUpper); } // Select an output directory. @@ -6547,22 +6542,17 @@ bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind, { // Look for a target property defining the target output directory // based on the target type. - const char* propertyName = nullptr; - std::string propertyNameStr = kind; - if (!propertyNameStr.empty()) { - propertyNameStr += "_OUTPUT_DIRECTORY"; - propertyName = propertyNameStr.c_str(); + std::string propertyName; + if (!kind.empty()) { + propertyName = cmStrCat(kind, "_OUTPUT_DIRECTORY"); } std::string conf = config; // Check for a per-configuration output directory target property. std::string configUpper = cmSystemTools::UpperCase(conf); - const char* configProp = nullptr; - std::string configPropStr = kind; - if (!configPropStr.empty()) { - configPropStr += "_OUTPUT_DIRECTORY_"; - configPropStr += configUpper; - configProp = configPropStr.c_str(); + std::string configProp; + if (!kind.empty()) { + configProp = cmStrCat(kind, "_OUTPUT_DIRECTORY_", configUpper); } // Select an output directory. -- cgit v0.12