Skip to content

Commit 45979e8

Browse files
authored
Merge pull request #7422 from hughbe/putenv-simplify
Simplify Windows implementation of Compilation::performSimpleCommand
2 parents 143c5a5 + fdf2613 commit 45979e8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/Driver/Compilation.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -747,13 +747,16 @@ int Compilation::performSingleCommand(const Job *Cmd) {
747747

748748
for (auto &envPair : Cmd->getExtraEnvironment()) {
749749
#if defined(_MSC_VER)
750-
llvm::SmallString<256> envStr = StringRef(envPair.first);
751-
envStr.append(StringRef("="));
752-
envStr.append(StringRef(envPair.second));
753-
_putenv(envStr.c_str());
750+
int envResult =_putenv_s(envPair.first, envPair.second);
754751
#else
755-
setenv(envPair.first, envPair.second, /*replacing=*/true);
752+
int envResult = setenv(envPair.first, envPair.second, /*replacing=*/true);
756753
#endif
754+
assert(envResult == 0 &&
755+
"expected environment variable to be set successfully");
756+
// Bail out early in release builds.
757+
if (envResult != 0) {
758+
return envResult;
759+
}
757760
}
758761

759762
return ExecuteInPlace(ExecPath, argv);

0 commit comments

Comments
 (0)