summaryrefslogtreecommitdiff
path: root/src/daemon.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 14:39:47 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commite8e7ed956f3914a3790e980df0862b26c30bd611 (patch)
tree53d3247c594717f79745ad20c5dd23bf16ed59ea /src/daemon.zig
parenta821fe82d8de3d407ebe104358b97719bd983727 (diff)
downloadpardes-e8e7ed956f3914a3790e980df0862b26c30bd611.tar.gz
pardes-e8e7ed956f3914a3790e980df0862b26c30bd611.zip
idioms #20, the bound in the type or the cut handled: of the 166 `catch unreachable` the pass kept, 64 stay where a reader checks the bound without arithmetic (an integer's digits, a declared field's size, and now the daemon's pid lists and the clock's two-digit fields written in their types), 69 texts print through Kind.Buf at their old size, 31 handle the failure once (a print into ename cut at its 320, paneText's line cut where its buffer fills, a log record or mouse report dropped rather than cut short, the question's letters that fit), Newcol's and pane/new's refusals are comptime strings, and dropUnsaved's too-long scratch name is null, not an empty sentinel
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/daemon.zig')
-rw-r--r--src/daemon.zig14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/daemon.zig b/src/daemon.zig
index dc86963d..f02c339e 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -359,10 +359,10 @@ pub fn setState(detached: bool) void {
/// This session's replica clients now, each its process's pid (0 when its
/// socket's peer is not known), for `--ps`.
pub fn clients(pids: []const libc.pid_t) void {
- var buf: [64]u8 = undefined;
+ var buf: ["clients".len + max_clients * " -2147483648".len]u8 = undefined;
var w: std.Io.Writer = .fixed(&buf);
- w.writeAll("clients") catch unreachable; // a literal fits 64
- for (pids[0..@min(pids.len, max_clients)]) |pid| w.print(" {d}", .{pid}) catch unreachable; // with max_clients pids, fits 64
+ w.writeAll("clients") catch unreachable; // a literal, its .len in buf's
+ for (pids[0..@min(pids.len, max_clients)]) |pid| w.print(" {d}", .{pid}) catch unreachable; // max_clients i32s, in buf's type
tell(w.buffered(), &.{});
}
@@ -761,15 +761,15 @@ const Daemon = struct {
/// TERM and marked, its pids answered; the shells of none kept, for
/// all of them.
fn kill(d: *Daemon, i: u8, named: ?[]const u8) void {
- var line: [msg_max]u8 = undefined;
+ var line: ["ok".len + max_conns * " -2147483648".len]u8 = undefined;
var w: std.Io.Writer = .fixed(&line);
- w.writeAll("ok") catch unreachable; // a literal fits msg_max
+ w.writeAll("ok") catch unreachable; // a literal, its .len in line's
var n: usize = 0;
for (&d.conns) |*s| if (s.fd >= 0 and s.kind != null) {
if (named) |want| if (!std.mem.eql(u8, s.named(), want)) continue;
s.killed = true;
_ = libc.kill(s.pid, .TERM);
- w.print(" {d}", .{s.pid}) catch unreachable; // max_conns pids after "ok" fit msg_max
+ w.print(" {d}", .{s.pid}) catch unreachable; // one i32 a conn, max_conns in line's type
n += 1;
};
if (named == null) {
@@ -954,7 +954,7 @@ const Daemon = struct {
return null;
}
if (count == 0) {
- w.print("no the detached session{s} running {s} {s}=<name>`", .{ if (others == 1) " is" else "s are", if (others == 1) "is" else "are each", other }) catch unreachable; // literals fit 511
+ w.print("no the detached session{s} running {s} {s}=<name>`", .{ if (others == 1) " is" else "s are", if (others == 1) "is" else "are each", other }) catch {}; // cut short, still 0-terminated
return null;
}
w.print("no {d} detached sessions are running; say which with --attach=<name>:", .{count}) catch unreachable; // a usize fits 511