diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 13:13:17 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 14:56:36 -0300 |
| commit | 4917ae452a15ff4f32d97d215a99fdcfaab29d61 (patch) | |
| tree | 56e25907532aed6222807503bc7904fc34781e31 | |
| parent | cf9e075d3537698e76a8fb22dc1a63622ca78c45 (diff) | |
| download | pardes-4917ae452a15ff4f32d97d215a99fdcfaab29d61.tar.gz pardes-4917ae452a15ff4f32d97d215a99fdcfaab29d61.zip | |
idioms #9, every catch unreachable this slice added is a fact of the code: each formats integers, literals, an error's name or a slice of a fixed array (the daemon's [128]u8 names, the cache's path_buf, main's cwd_buf, those two buffers now sized from their arrays), so all 39 stay, each with its reason on its own line
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | src/Db.zig | 4 | ||||
| -rw-r--r-- | src/Handover.zig | 3 | ||||
| -rw-r--r-- | src/daemon.zig | 27 | ||||
| -rw-r--r-- | src/dump.zig | 4 | ||||
| -rw-r--r-- | src/main.zig | 4 | ||||
| -rw-r--r-- | src/upgrade.zig | 4 |
6 files changed, 21 insertions, 25 deletions
@@ -1114,8 +1114,8 @@ pub const Cache = struct { } }{ .cap = c.cap, .went = &went }) catch return; if (!went) return; - var new_buf: [4200]u8 = undefined; - const new = std.fmt.bufPrint(&new_buf, "{s}.new", .{c.path()}) catch unreachable; // a path of 4096 fits 4200 + var new_buf: [c.path_buf.len + ".new".len]u8 = undefined; + const new = std.fmt.bufPrint(&new_buf, "{s}.new", .{c.path()}) catch unreachable; // path_buf's [4096]u8 and ".new" fit const cwd = std.Io.Dir.cwd(); const file = cwd.createFile(io, new, .{ .read = true, .truncate = true }) catch return; var buffer: std.Io.Writer.Allocating = .init(std.heap.c_allocator); diff --git a/src/Handover.zig b/src/Handover.zig index abba41a8..0abcf859 100644 --- a/src/Handover.zig +++ b/src/Handover.zig @@ -218,8 +218,7 @@ fn dumpCarried(p: *Pardes, kind: Kind, at: usize, ids: []const usize, seq: u32) } }{ .w = &w, .value = &value }); var name: [32]u8 = undefined; - // "handover-" and a u32 fit 32. - return pardes.Db.image(p.gpa, std.fmt.bufPrint(&name, "handover-{d}", .{seq}) catch unreachable, buf.written(), w.blobs.items, ids.len); + return pardes.Db.image(p.gpa, std.fmt.bufPrint(&name, "handover-{d}", .{seq}) catch unreachable, buf.written(), w.blobs.items, ids.len); // a u32 fits 32 } /// Whether `bytes` are a handover's dump (`dumpCarried`'s, or an older diff --git a/src/daemon.zig b/src/daemon.zig index 009b81e3..dc86963d 100644 --- a/src/daemon.zig +++ b/src/daemon.zig @@ -361,9 +361,8 @@ 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); - // "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; + 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 tell(w.buffered(), &.{}); } @@ -764,14 +763,13 @@ const Daemon = struct { fn kill(d: *Daemon, i: u8, named: ?[]const u8) void { var line: [msg_max]u8 = undefined; var w: std.Io.Writer = .fixed(&line); - // "ok" and max_conns pids fit msg_max. - w.writeAll("ok") catch unreachable; + w.writeAll("ok") catch unreachable; // a literal fits msg_max 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; + w.print(" {d}", .{s.pid}) catch unreachable; // max_conns pids after "ok" fit msg_max n += 1; }; if (named == null) { @@ -789,7 +787,7 @@ const Daemon = struct { fn list(d: *Daemon, i: u8) void { var line: [msg_max]u8 = undefined; var w: std.Io.Writer = .fixed(&line); - w.print("daemon {d}\n", .{libc.getpid()}) catch unreachable; // the first line of msg_max + w.print("daemon {d}\n", .{libc.getpid()}) catch unreachable; // a pid fits msg_max for (&d.conns, 0..) |*s, k| if (s.fd >= 0 and s.kind != null) { w.print("session {d} {t} {s} {s}\n", .{ s.pid, s.kind.?, if (s.detached) "detached" else "attached", s.named() }) catch break; for (s.clients[0..s.nclients]) |pid| w.print("client {d}\n", .{pid}) catch break; @@ -862,7 +860,7 @@ const Daemon = struct { .adopt => { var line: [msg_max]u8 = undefined; var w: std.Io.Writer = .fixed(&line); - w.writeAll("adopted") catch unreachable; // the first word of msg_max + w.writeAll("adopted") catch unreachable; // a literal fits msg_max var fds: [max_fds]c_int = undefined; var given: [max_fds]*Held = undefined; var n: usize = 0; @@ -888,8 +886,7 @@ const Daemon = struct { } t.detached = false; var line: [32]u8 = undefined; - // "ok " and a pid_t's at most 11 digits fit 32. - return d.reply(i, std.fmt.bufPrint(&line, "ok {d}", .{t.pid}) catch unreachable, &.{}); + return d.reply(i, std.fmt.bufPrint(&line, "ok {d}", .{t.pid}) catch unreachable, &.{}); // a pid fits 32 }, } } @@ -936,7 +933,7 @@ const Daemon = struct { found = @intCast(i); }; if (count == 1) { - _ = std.fmt.bufPrint(why, "other {s}", .{d.conns[found.?].named()}) catch unreachable; // a name of 128 fits 512 + _ = std.fmt.bufPrint(why, "other {s}", .{d.conns[found.?].named()}) catch unreachable; // a [128]u8 field's name fits 512 return null; } count = 0; @@ -948,19 +945,19 @@ const Daemon = struct { only = s; }; if (found == null and sessions == 1) { - _ = std.fmt.bufPrint(why, "other {s}", .{only.?.named()}) catch unreachable; // a name of 128 fits 512 + _ = std.fmt.bufPrint(why, "other {s}", .{only.?.named()}) catch unreachable; // a [128]u8 field's name fits 512 return null; } } if (count == 0 and others == 0) { - w.writeAll("no no detached session is running") catch unreachable; // fits 511 + w.writeAll("no no detached session is running") catch unreachable; // a literal fits 511 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; // fits 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 unreachable; // literals fit 511 return null; } - w.print("no {d} detached sessions are running; say which with --attach=<name>:", .{count}) catch unreachable; // fits 511 + w.print("no {d} detached sessions are running; say which with --attach=<name>:", .{count}) catch unreachable; // a usize fits 511 for (&d.conns) |*s| if (s.fd >= 0 and s.detached and s.kind == k) { w.print(" {s}", .{s.named()}) catch {}; }; diff --git a/src/dump.zig b/src/dump.zig index 04d08142..06721be1 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -254,7 +254,7 @@ pub fn check(gpa: std.mem.Allocator, bytes: []const u8, why: *[256]u8) !void { error.NoDump => "it holds no dump", error.OutOfMemory => "out of memory", else => "it is no dump of pardes's", - }}) catch unreachable; // a short phrase or an error's name fits 255 + }}) catch unreachable; // a literal or an error's name fits 255 why[said.len] = 0; return err; }; @@ -266,7 +266,7 @@ pub fn check(gpa: std.mem.Allocator, bytes: []const u8, why: *[256]u8) !void { error.BadDump => "it does not begin as one", error.EndOfDump => "it is cut short", else => @errorName(err), - }}) catch unreachable; // a short phrase or an error's name fits 255 + }}) catch unreachable; // a literal or an error's name fits 255 why[said.len] = 0; return err; }; diff --git a/src/main.zig b/src/main.zig index 3401c0b4..7f6d1a05 100644 --- a/src/main.zig +++ b/src/main.zig @@ -156,8 +156,8 @@ fn pageInto(io: std.Io, gpa: std.mem.Allocator, dial: []const u8, text: []const const plain = for (cwd) |c| { if (c < ' ' or c == 0x7f) break false; } else !pardes.filesystem.deniedAbove(cwd); - var line_buf: [4200]u8 = undefined; - const dir_line = std.fmt.bufPrint(&line_buf, "{s}\n", .{if (plain) cwd else ""}) catch unreachable; // a cwd of 4096 fits 4200 + var line_buf: [cwd_buf.len + 1]u8 = undefined; + const dir_line = std.fmt.bufPrint(&line_buf, "{s}\n", .{if (plain) cwd else ""}) catch unreachable; // a cwd out of cwd_buf and "\n" fit // Its serial read back on the open that asked, once the text is in: // another client's exec meanwhile can never send it into that // client's pane. diff --git a/src/upgrade.zig b/src/upgrade.zig index 5bd83a30..5a338ae2 100644 --- a/src/upgrade.zig +++ b/src/upgrade.zig @@ -285,9 +285,9 @@ pub fn check(path: [:0]const u8, buf: []u8) Checked { else if (libc.W.IFEXITED(s) and libc.W.EXITSTATUS(s) == 127) "would not start" else if (libc.W.IFEXITED(s) and libc.W.EXITSTATUS(s) != 0) - std.fmt.bufPrint(&tail, "exited {d} at --version", .{libc.W.EXITSTATUS(s)}) catch unreachable // fits 96 + std.fmt.bufPrint(&tail, "exited {d} at --version", .{libc.W.EXITSTATUS(s)}) catch unreachable // a status number fits 96 else if (libc.W.IFSIGNALED(s)) - std.fmt.bufPrint(&tail, "died of signal {d} at --version", .{libc.W.TERMSIG(s)}) catch unreachable // fits 96 + std.fmt.bufPrint(&tail, "died of signal {d} at --version", .{libc.W.TERMSIG(s)}) catch unreachable // a signal number fits 96 else "does not answer --version as a pardes does"; return .{ .no = std.fmt.bufPrint(buf, "Upgrade: {s} {s}; this session stays as it is", .{ path[0..@min(path.len, 400)], how }) catch "Upgrade: the new pardes would not start; this session stays as it is" }; |
