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.
This commit is contained in:
Andrew Kelley 2020-12-29 14:02:12 -07:00
parent 0b46c27333
commit 8078d8cd3f

View File

@ -212,16 +212,18 @@ pub const ChildProcess = struct {
if (poll_fds[0].revents & os.POLLIN != 0) {
// stdout is ready.
const new_capacity = std.math.min(stdout.items.len + bump_amt, max_output_bytes);
if (new_capacity == stdout.capacity) return error.StdoutStreamTooLong;
try stdout.ensureCapacity(new_capacity);
stdout.items.len += try os.read(poll_fds[0].fd, stdout.unusedCapacitySlice());
const buf = stdout.unusedCapacitySlice();
if (buf.len == 0) return error.StdoutStreamTooLong;
stdout.items.len += try os.read(poll_fds[0].fd, buf);
}
if (poll_fds[1].revents & os.POLLIN != 0) {
// stderr is ready.
const new_capacity = std.math.min(stderr.items.len + bump_amt, max_output_bytes);
if (new_capacity == stderr.capacity) return error.StderrStreamTooLong;
try stderr.ensureCapacity(new_capacity);
stderr.items.len += try os.read(poll_fds[1].fd, stderr.unusedCapacitySlice());
const buf = stderr.unusedCapacitySlice();
if (buf.len == 0) return error.StderrStreamTooLong;
stderr.items.len += try os.read(poll_fds[1].fd, buf);
}
// Exclude the fds that signaled an error.