diff options
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/Unix/Program.inc | 11 | ||||
-rw-r--r-- | llvm/lib/Support/Windows/Program.inc | 3 |
2 files changed, 8 insertions, 6 deletions
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc index 0670ad39c9a..0f45df1a0da 100644 --- a/llvm/lib/Support/Unix/Program.inc +++ b/llvm/lib/Support/Unix/Program.inc @@ -63,11 +63,12 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name, if (Name.find('/') != StringRef::npos) return std::string(Name); - if (Paths.empty()) { - SmallVector<StringRef, 16> SearchPaths; - SplitString(std::getenv("PATH"), SearchPaths, ":"); - return findProgramByName(Name, SearchPaths); - } + SmallVector<StringRef, 16> EnvironmentPaths; + if (Paths.empty()) + if (const char *PathEnv = std::getenv("PATH")) { + SplitString(PathEnv, EnvironmentPaths, ":"); + Paths = EnvironmentPaths; + } for (auto Path : Paths) { if (Path.empty()) diff --git a/llvm/lib/Support/Windows/Program.inc b/llvm/lib/Support/Windows/Program.inc index 6467dddb3da..5bd9021a1b7 100644 --- a/llvm/lib/Support/Windows/Program.inc +++ b/llvm/lib/Support/Windows/Program.inc @@ -62,7 +62,8 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name, SmallVector<StringRef, 12> PathExts; PathExts.push_back(""); PathExts.push_back(".exe"); // FIXME: This must be in %PATHEXT%. - SplitString(std::getenv("PATHEXT"), PathExts, ";"); + if (const char *PathExtEnv = std::getenv("PATHEXT")) + SplitString(PathExtEnv, PathExts, ";"); SmallVector<wchar_t, MAX_PATH> U16Result; DWORD Len = MAX_PATH; |