authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2021-09-17 12:43:47-07:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-09-19 13:52:56+02:00
log224d4de747d02f4b7add6a7e18512467b6d33569
tree8e16693234c535d50edbc7217ea6a84b97b501b3
parent59f5053beda7087a73983835e9f7e00dc3143d59

Improve ensureTotalCapacity call in ChildProcess.collectOutputWindows

Take current len and max_output_bytes into account instead of unconditionally using bump_amt

1 files changed, 2 insertions(+), 1 deletions(-)

lib/std/child_process.zig+2-1
...@@ -276,7 +276,8 @@ pub const ChildProcess = struct {...@@ -276,7 +276,8 @@ pub const ChildProcess = struct {
276276
277 // Windows Async IO requires an initial call to ReadFile before waiting on the handle277 // Windows Async IO requires an initial call to ReadFile before waiting on the handle
278 for ([_]u1{ 0, 1 }) |i| {278 for ([_]u1{ 0, 1 }) |i| {
279 try outs[i].ensureTotalCapacity(bump_amt);279 const new_capacity = std.math.min(outs[i].items.len + bump_amt, max_output_bytes);
280 try outs[i].ensureTotalCapacity(new_capacity);
280 const buf = outs[i].unusedCapacitySlice();281 const buf = outs[i].unusedCapacitySlice();
281 _ = windows.kernel32.ReadFile(handles[i], buf.ptr, math.cast(u32, buf.len) catch maxInt(u32), null, &overlapped[i]);282 _ = windows.kernel32.ReadFile(handles[i], buf.ptr, math.cast(u32, buf.len) catch maxInt(u32), null, &overlapped[i]);
282 wait_objects[wait_object_count] = handles[i];283 wait_objects[wait_object_count] = handles[i];