authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-29 14:02:12-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-29 14:02:12-07:00
log8078d8cd3fb989b0c7a26adde0ee2486e1f473f8
tree1c0434306f2edeab4e83e908c3b3f678ffd7f8eb
parent0b46c27333960553226abd4cc7aed10e07a14b06

std.ChildProcess: fix max_output_bytes handling

The previous logic had a false positive of returning an error when in fact the maximum number of output bytes had not been exceeded.

1 files changed, 6 insertions(+), 4 deletions(-)

lib/std/child_process.zig+6-4
......@@ -212,16 +212,18 @@ pub const ChildProcess = struct {
212212 if (poll_fds[0].revents & os.POLLIN != 0) {
213213 // stdout is ready.
214214 const new_capacity = std.math.min(stdout.items.len + bump_amt, max_output_bytes);
215 if (new_capacity == stdout.capacity) return error.StdoutStreamTooLong;
216215 try stdout.ensureCapacity(new_capacity);
217 stdout.items.len += try os.read(poll_fds[0].fd, stdout.unusedCapacitySlice());
216 const buf = stdout.unusedCapacitySlice();
217 if (buf.len == 0) return error.StdoutStreamTooLong;
218 stdout.items.len += try os.read(poll_fds[0].fd, buf);
218219 }
219220 if (poll_fds[1].revents & os.POLLIN != 0) {
220221 // stderr is ready.
221222 const new_capacity = std.math.min(stderr.items.len + bump_amt, max_output_bytes);
222 if (new_capacity == stderr.capacity) return error.StderrStreamTooLong;
223223 try stderr.ensureCapacity(new_capacity);
224 stderr.items.len += try os.read(poll_fds[1].fd, stderr.unusedCapacitySlice());
224 const buf = stderr.unusedCapacitySlice();
225 if (buf.len == 0) return error.StderrStreamTooLong;
226 stderr.items.len += try os.read(poll_fds[1].fd, buf);
225227 }
226228
227229 // Exclude the fds that signaled an error.