Skip to content

Commit 365a358

Browse files
committed
Windows: Fix Command::env_clear so it works
Previously, it would error unless at least one new environment variable was added.
1 parent 9839f9c commit 365a358

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/std/src/sys/windows/process.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,12 @@ fn make_envp(maybe_env: Option<BTreeMap<EnvKey, OsString>>) -> io::Result<(*mut
530530
if let Some(env) = maybe_env {
531531
let mut blk = Vec::new();
532532

533+
// If there are no environment variables to set then signal this by
534+
// pushing a null.
535+
if env.is_empty() {
536+
blk.push(0);
537+
}
538+
533539
for (k, v) in env {
534540
blk.extend(ensure_no_nuls(k.0)?.encode_wide());
535541
blk.push('=' as u16);

0 commit comments

Comments
 (0)