mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
wasm: avoids allocating zero length buffers for args or env
I was testing this with wazero, which defaults to not propagate any env variables. This ensures we don't try to allocate zero length buffers when there are no results from either function. Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
parent
c70a3d9022
commit
7208e1ff87
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user