namespace {
void CreateEnvironmentBuffer(const Environment &env,
std::vector<char> &buffer) {
- // The buffer is a list of null-terminated UTF-16 strings, followed by an
- // extra L'\0' (two bytes of 0). An empty environment must have one
- // empty string, followed by an extra L'\0'.
+ if (env.size() == 0)
+ return;
+
+ // Environment buffer is a null terminated list of null terminated strings
for (const auto &KV : env) {
std::wstring warg;
if (llvm::ConvertUTF8toWide(Environment::compose(KV), warg)) {
// One null wchar_t (to end the block) is two null bytes
buffer.push_back(0);
buffer.push_back(0);
- // Insert extra two bytes, just in case the environment was empty.
- buffer.push_back(0);
- buffer.push_back(0);
}
bool GetFlattenedWindowsCommandString(Args args, std::string &command) {
LPVOID env_block = nullptr;
::CreateEnvironmentBuffer(launch_info.GetEnvironment(), environment);
- env_block = environment.data();
+ if (!environment.empty())
+ env_block = environment.data();
executable = launch_info.GetExecutableFile().GetPath();
GetFlattenedWindowsCommandString(launch_info.GetArguments(), commandLine);
"Environment variable 'MY_ENV_VAR' successfully passed."])
@skipIfRemote # it doesn't make sense to send host env to remote target
+ @skipIf(oslist=["windows"])
def test_pass_host_env_vars(self):
"""Test that the host env vars are passed to the launched process."""
self.build()