commit 8078d8cd3fb989b0c7a26adde0ee2486e1f473f8 (tree)
parent 0b46c27333960553226abd4cc7aed10e07a14b06
Author: Andrew Kelley <andrew@ziglang.org>
Date: Tue, 29 Dec 2020 14:02:12 -0700
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.
Diffstat:
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig
@@ -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.