diff --git a/lib/std/process.zig b/lib/std/process.zig index 138f5feeb8..b901a9f0fa 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -293,6 +293,10 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap { return os.unexpectedErrno(environ_sizes_get_ret); } + if (environ_count == 0) { + return result; + } + var environ = try allocator.alloc([*:0]u8, environ_count); defer allocator.free(environ); var environ_buf = try allocator.alloc(u8, environ_buf_size); @@ -468,6 +472,10 @@ pub const ArgIteratorWasi = struct { else => |err| return os.unexpectedErrno(err), } + if (count == 0) { + return &[_][:0]u8{}; + } + var argv = try allocator.alloc([*:0]u8, count); defer allocator.free(argv);