Improve ensureTotalCapacity call in ChildProcess.collectOutputWindows

Take current len and max_output_bytes into account instead of unconditionally using bump_amt
This commit is contained in:
Ryan Liptak 2021-09-17 12:43:47 -07:00 committed by Isaac Freund
parent 59f5053bed
commit 224d4de747

View File

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