From dde4979f59bec754b7909a81a40763850f3c29c0 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 12:38:55 -0300 Subject: idioms #5, more formats that cannot overflow: /proc paths of a pid, the daemon's pty, close and clients words, a pid or a serial for the environment, a capture's header and status line and a cache's .new name are catch unreachable with their reason, where a catch return, null or continue stood for an overflow no buffer here can have Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/daemon.zig | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/daemon.zig') diff --git a/src/daemon.zig b/src/daemon.zig index a4e2c2d9..118fa58a 100644 --- a/src/daemon.zig +++ b/src/daemon.zig @@ -341,14 +341,14 @@ fn tell(words: []const u8, fds: []const c_int) void { /// A shell forked on `master` (host_io.forkShell): the daemon keeps a dup. pub fn pty(pid: libc.pid_t, master: c_int) void { var buf: [32]u8 = undefined; - tell(std.fmt.bufPrint(&buf, "pty {d}", .{pid}) catch return, &.{master}); + tell(std.fmt.bufPrint(&buf, "pty {d}", .{pid}) catch unreachable, &.{master}); // a pid fits 32 } /// The pty of `pid` closed here: the daemon lets its dup go too. pub fn closed(pid: libc.pid_t) void { if (pid <= 0) return; var buf: [32]u8 = undefined; - tell(std.fmt.bufPrint(&buf, "close {d}", .{pid}) catch return, &.{}); + tell(std.fmt.bufPrint(&buf, "close {d}", .{pid}) catch unreachable, &.{}); // a pid fits 32 } pub fn setState(detached: bool) void { @@ -360,8 +360,9 @@ pub fn setState(detached: bool) void { pub fn clients(pids: []const libc.pid_t) void { var buf: [64]u8 = undefined; var w: std.Io.Writer = .fixed(&buf); - w.writeAll("clients") catch return; - for (pids[0..@min(pids.len, max_clients)]) |pid| w.print(" {d}", .{pid}) catch return; + // "clients" and max_clients pids fit 64. + w.writeAll("clients") catch unreachable; + for (pids[0..@min(pids.len, max_clients)]) |pid| w.print(" {d}", .{pid}) catch unreachable; tell(w.buffered(), &.{}); } -- cgit v1.3