[PATCH] D140019: [WindowsDriver] Improve VSInstallPath check for IDE subdirectory

Dimitry Andric via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 06:02:14 PST 2022


dim created this revision.
dim added reviewers: mstorsjo, thakis, MaskRay.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
dim requested review of this revision.
Herald added a project: LLVM.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140019

Files:
  llvm/lib/WindowsDriver/MSVCPaths.cpp


Index: llvm/lib/WindowsDriver/MSVCPaths.cpp
===================================================================
--- llvm/lib/WindowsDriver/MSVCPaths.cpp
+++ llvm/lib/WindowsDriver/MSVCPaths.cpp
@@ -705,8 +705,10 @@
       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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140019.482829.patch
Type: text/x-patch
Size: 813 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221214/6d4a2a4f/attachment.bin>


More information about the llvm-commits mailing list