Commit 29512f0edd

Andrew Kelley <andrew@ziglang.org>
2024-07-03 22:28:44
Compilation: don't give len=0 bufs to pwritev
The OS returns EFAULT for undefined pointers, even when len=0.
1 parent cac7e5a
Changed files (1)
src/Compilation.zig
@@ -2827,6 +2827,9 @@ pub fn saveState(comp: *Compilation) !void {
 }
 
 fn addBuf(bufs_list: []std.posix.iovec_const, bufs_len: *usize, buf: []const u8) void {
+    // Even when len=0, the undefined pointer might cause EFAULT.
+    if (buf.len == 0) return;
+
     const i = bufs_len.*;
     bufs_len.* = i + 1;
     bufs_list[i] = .{