From fbd5d4e87fe83c4dea40f96d2961a4618cfa0b4e Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 17 Oct 2024 14:45:41 -0400 Subject: [PATCH] cmFind*Command: Store candidate paths as local variables --- Source/cmFindLibraryCommand.cxx | 17 +++++++---------- Source/cmFindProgramCommand.cxx | 20 +++++++------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 9df7665ff4..3d3ee2527f 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -220,9 +220,6 @@ struct cmFindLibraryHelper }; std::vector Names; - // Current full path under consideration. - std::string TestPath; - void RegexFromLiteral(std::string& out, std::string const& in); void RegexFromList(std::string& out, cmList const& in); size_type GetPrefixIndex(std::string const& prefix) @@ -423,13 +420,13 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, // one cannot tell just from the library name whether it is a static // library or an import library). if (name.TryRaw) { - this->TestPath = cmStrCat(path, name.Raw); + std::string testPath = cmStrCat(path, name.Raw); - const bool exists = cmSystemTools::FileExists(this->TestPath, true); + const bool exists = cmSystemTools::FileExists(testPath, true); if (!exists) { this->DebugLibraryFailed(name.Raw, path); } else { - auto testPath = cmSystemTools::CollapseFullPath(this->TestPath); + testPath = cmSystemTools::CollapseFullPath(testPath); if (this->Validate(testPath)) { this->DebugLibraryFound(name.Raw, path); this->BestPath = testPath; @@ -456,10 +453,10 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, std::string const& testName = origName; #endif if (name.Regex.find(testName)) { - this->TestPath = cmStrCat(path, origName); + std::string testPath = cmStrCat(path, origName); // Make sure the path is readable and is not a directory. - if (cmSystemTools::FileExists(this->TestPath, true)) { - if (!this->Validate(cmSystemTools::CollapseFullPath(this->TestPath))) { + if (cmSystemTools::FileExists(testPath, true)) { + if (!this->Validate(cmSystemTools::CollapseFullPath(testPath))) { continue; } @@ -480,7 +477,7 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, (prefix == bestPrefix && suffix == bestSuffix && (major > bestMajor || (major == bestMajor && minor > bestMinor)))) { - this->BestPath = this->TestPath; + this->BestPath = testPath; bestPrefix = prefix; bestSuffix = suffix; bestMajor = major; diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index fee1c47a46..d73d38adb0 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -48,12 +48,6 @@ struct cmFindProgramHelper // Current names under consideration. std::vector Names; - // Current name with extension under consideration. - std::string TestNameExt; - - // Current full path under consideration. - std::string TestPath; - // Debug state cmFindBaseDebugState DebugSearches; cmMakefile* Makefile; @@ -91,14 +85,14 @@ struct cmFindProgramHelper if (!ext.empty() && cmHasSuffix(name, ext)) { return false; } - this->TestNameExt = cmStrCat(name, ext); - this->TestPath = cmSystemTools::CollapseFullPath( - this->TestNameExt, path); - bool exists = this->FileIsValid(this->TestPath); - exists ? this->DebugSearches.FoundAt(this->TestPath) - : this->DebugSearches.FailedAt(this->TestPath); + std::string testNameExt = cmStrCat(name, ext); + std::string testPath = + cmSystemTools::CollapseFullPath(testNameExt, path); + bool exists = this->FileIsValid(testPath); + exists ? this->DebugSearches.FoundAt(testPath) + : this->DebugSearches.FailedAt(testPath); if (exists) { - this->BestPath = this->TestPath; + this->BestPath = testPath; return true; } return false;