[llvm] cc40dac - [WindowsDriver] Improve VSInstallPath check for IDE subdirectory
Dimitry Andric via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 15 12:32:12 PST 2022
Author: Dimitry Andric
Date: 2022-12-15T21:29:50+01:00
New Revision: cc40dacbd0b736522d0254fb5525cde22bd5f166
URL: https://github.com/llvm/llvm-project/commit/cc40dacbd0b736522d0254fb5525cde22bd5f166
DIFF: https://github.com/llvm/llvm-project/commit/cc40dacbd0b736522d0254fb5525cde22bd5f166.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..d7703e9945e9f 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