std.process.Child: comptime assert to protect prog_fileno

documenting my assumptions via comptime assertion
This commit is contained in:
Andrew Kelley
2024-05-26 11:10:45 -07:00
parent e8907f9e9c
commit e2e61f3296

View File

@@ -610,6 +610,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
for (self.argv, 0..) |arg, i| argv_buf[i] = (try arena.dupeZ(u8, arg)).ptr;
const prog_fileno = 3;
comptime assert(@max(posix.STDIN_FILENO, posix.STDOUT_FILENO, posix.STDERR_FILENO) + 1 == prog_fileno);
const envp: [*:null]const ?[*:0]const u8 = m: {
const prog_fd: i32 = if (prog_pipe[1] == -1) -1 else prog_fileno;