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
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());