[llvm] 2a48c5f - [WindowsDriver] Improve VSInstallPath check for IDE subdirectory
Dimitry Andric via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 15 12:38:50 PST 2022
Author: Dimitry Andric
Date: 2022-12-15T21:38:07+01:00
New Revision: 2a48c5f5d597002b7e315126c69672bc11185d90
URL: https://github.com/llvm/llvm-project/commit/2a48c5f5d597002b7e315126c69672bc11185d90
DIFF: https://github.com/llvm/llvm-project/commit/2a48c5f5d597002b7e315126c69672bc11185d90.diff
LOG: [WindowsDriver] Improve VSInstallPath check for IDE subdirectory
This avoids potential memory allocation failures, if VSInstallPath is
not empty, but also does not contain the string "\Common7\IDE".
Fixes: https://github.com/llvm/llvm-project/issues/59434
Reviewed By: mstorsjo
Differential Revision: https://reviews.llvm.org/D140019
Added:
Modified:
llvm/lib/WindowsDriver/MSVCPaths.cpp
Removed:
################################################################################
diff --git a/llvm/lib/WindowsDriver/MSVCPaths.cpp b/llvm/lib/WindowsDriver/MSVCPaths.cpp
index fb8991985a9df..d8d656fc46e4e 100644
--- a/llvm/lib/WindowsDriver/MSVCPaths.cpp
+++ b/llvm/lib/WindowsDriver/MSVCPaths.cpp
@@ -705,8 +705,10 @@ bool findVCToolChainViaRegistry(std::string &Path, ToolsetLayout &VSLayout) {
getSystemRegistryString(R"(SOFTWARE\Microsoft\VCExpress\$VERSION)",
"InstallDir", VSInstallPath, nullptr)) {
if (!VSInstallPath.empty()) {
- SmallString<256> VCPath(StringRef(VSInstallPath.c_str(),
- VSInstallPath.find(R"(\Common7\IDE)")));
+ auto pos = VSInstallPath.find(R"(\Common7\IDE)");
+ if (pos == std::string::npos)
+ return false;
+ SmallString<256> VCPath(StringRef(VSInstallPath.c_str(), pos));
sys::path::append(VCPath, "VC");
Path = std::string(VCPath.str());
More information about the llvm-commits
mailing list