summaryrefslogtreecommitdiff
path: root/src/ninep/events.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/events.zig')
-rw-r--r--src/ninep/events.zig24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index 6fd0d345..a25b97b2 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -131,7 +131,7 @@ pub fn noteRetire(p: *Pardes, pane: *Pane) void {
// hears the end.
if (pane.prompt == .repl_choice or pane.prompt == .del_side or pane.prompt == .save) {
var rec: [32]u8 = undefined;
- notePath(p, "answer", std.fmt.bufPrint(&rec, "{d} -", .{pane.serial}) catch "");
+ notePath(p, "answer", std.fmt.bufPrint(&rec, "{d} -", .{pane.serial}) catch unreachable); // a u32 fits 32
}
noteLog(p, .del, pane);
}
@@ -174,7 +174,7 @@ pub fn noteLogAs(p: *Pardes, kind: LogKind, pane: *Pane, path: []const u8) void
var name_buf: [4 * 4096]u8 = undefined;
// As /index shows it: a newline in the name is `\n`.
const name = shown(path, &name_buf);
- pushLog(p, std.fmt.bufPrint(&buf, "{s} {d} {s}\n", .{ @tagName(kind), pane.serial, name }) catch return);
+ pushLog(p, std.fmt.bufPrint(&buf, "{s} {d} {s}\n", .{ @tagName(kind), pane.serial, name }) catch unreachable); // name is at most name_buf's
}
/// Records `msg <serial> <text>` for what the editor said, `-` for no pane.
@@ -191,7 +191,7 @@ pub fn noteMessage(p: *Pardes, serial: u32, said_stamped: []const u8) void {
pushCounting(p, (if (serial == 0)
std.fmt.bufPrint(&buf, "msg - {s}{s}\n", .{ kept, cut })
else
- std.fmt.bufPrint(&buf, "msg {d} {s}{s}\n", .{ serial, kept, cut })) catch return, said);
+ std.fmt.bufPrint(&buf, "msg {d} {s}{s}\n", .{ serial, kept, cut })) catch unreachable, said); // kept is at most cap
}
/// `notePath` for an `err` record: the same one again straight after is
@@ -199,7 +199,7 @@ pub fn noteMessage(p: *Pardes, serial: u32, said_stamped: []const u8) void {
pub fn noteErrCounted(p: *Pardes, text: []const u8) void {
bootFirst(p);
var buf: [pardes.memory.limits.host_path_cap + 16]u8 = undefined;
- pushCounting(p, std.fmt.bufPrint(&buf, "err {s}\n", .{text}) catch return, text);
+ pushCounting(p, std.fmt.bufPrint(&buf, "err {s}\n", .{text[0..@min(text.len, buf.len - 16)]}) catch unreachable, text);
}
/// Records `<what> <path>`: `dump <path>` when a Dump is written,
@@ -207,7 +207,8 @@ pub fn noteErrCounted(p: *Pardes, text: []const u8) void {
pub fn notePath(p: *Pardes, what: []const u8, path: []const u8) void {
bootFirst(p);
var buf: [pardes.memory.limits.host_path_cap + 16]u8 = undefined;
- pushLog(p, std.fmt.bufPrint(&buf, "{s} {s}\n", .{ what, path }) catch return);
+ // unreachable: a record's word is a short literal, and the path is cut to fit.
+ pushLog(p, std.fmt.bufPrint(&buf, "{s} {s}\n", .{ what, path[0..@min(path.len, buf.len - 16)] }) catch unreachable);
}
/// Records `err <serial|-> <file>: <why>` for a write that was refused or
@@ -228,17 +229,17 @@ pub fn noteError(p: *Pardes, req: Req, reply: Reply) void {
// The root's exec or look ran at the keyboard's pane: its
// failure is that pane's, as a click there would be.
if ((f == .exec or f == .look) and p.fs.ran_at != 0)
- serial = std.fmt.bufPrint(&name, "{d}", .{p.fs.ran_at}) catch "-";
+ serial = std.fmt.bufPrint(&name, "{d}", .{p.fs.ran_at}) catch unreachable; // a u32 fits 32
},
.col => |c| {
serial = "-";
file = (if (c.file == .dir)
std.fmt.bufPrint(&name, "col/{d}", .{c.serial})
else
- std.fmt.bufPrint(&name, "col/{d}/{s}", .{ c.serial, @tagName(c.file) })) catch "col";
+ std.fmt.bufPrint(&name, "col/{d}/{s}", .{ c.serial, @tagName(c.file) })) catch unreachable; // a u32 and a file's name fit 32
},
.pane => |pt| {
- serial = std.fmt.bufPrint(&name, "{d}", .{pt.serial}) catch "-";
+ serial = std.fmt.bufPrint(&name, "{d}", .{pt.serial}) catch unreachable; // a u32 fits 32
file = switch (pt.file) {
.pty_ctl => "pty/ctl",
.pty_status => "pty/status",
@@ -255,7 +256,7 @@ pub fn noteError(p: *Pardes, req: Req, reply: Reply) void {
const reason = if (why.len > file.len + 2 and std.ascii.startsWithIgnoreCase(why, file) and std.mem.startsWith(u8, why[file.len..], ": ")) why[file.len + 2 ..] else why;
// A long reason is cut between words, with an ellipsis, never mid-word.
const kept = pardes.Messages.clip(reason, 200);
- const record = std.fmt.bufPrint(&buf, "err {s} {s}: {s}{s}\n", .{ serial, file, kept, if (kept.len < reason.len) "…" else "" }) catch return;
+ const record = std.fmt.bufPrint(&buf, "err {s} {s}: {s}{s}\n", .{ serial, file, kept, if (kept.len < reason.len) "…" else "" }) catch unreachable; // 10 + 32 + 200 + 11 fit 256
for (record[0 .. record.len - 1]) |*c| if (c.* < ' ') {
c.* = ' ';
};
@@ -298,7 +299,8 @@ fn pushCounting(p: *Pardes, raw: []u8, full: []const u8) void {
};
if (!std.mem.eql(u8, said, record[0 .. record.len - 1]) or p.fs.log_full_hash != full_hash) return pushLog(p, record);
var counted: [pardes.Messages.LoggedMessage.cap + 64]u8 = undefined;
- const again = std.fmt.bufPrint(&counted, "{s} (x{d})\n", .{ said, times +| 1 }) catch return;
+ // A repeat too long to count is pushed as a line of its own.
+ const again = std.fmt.bufPrint(&counted, "{s} (x{d})\n", .{ said, times +| 1 }) catch return pushLog(p, record);
if (!followerRead(p, last.seq)) p.fs.log.buf.shrinkRetainingCapacity(last.at);
pushLog(p, again);
}
@@ -441,7 +443,7 @@ pub const LogOpen = struct {
/// An open freezes the ring's text, so `cat log` answers what happened lately
/// and ends; `next` is where a follower picks up after it.
-pub fn freezeLog(p: *Pardes) !LogOpen {
+pub fn freezeLog(p: *Pardes) error{OutOfMemory}!LogOpen {
var text: std.ArrayList(u8) = .empty;
errdefer text.deinit(p.gpa);
var at = p.fs.log.head;