summaryrefslogtreecommitdiff
path: root/src/ninep/tree.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/tree.zig')
-rw-r--r--src/ninep/tree.zig18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index d15ddd53..2117916d 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -453,12 +453,14 @@ pub fn stageDirent(out: *std.ArrayList(u8), gpa: std.mem.Allocator, node: u64, d
std.mem.writeInt(u64, head[0..8], node, .little);
head[8] = @intFromBool(dir);
head[9] = @intCast(name.len);
- out.appendSlice(gpa, &head) catch return;
- out.appendSlice(gpa, name) catch return;
+ // Head and name both or neither: a head alone would corrupt the listing.
+ out.ensureUnusedCapacity(gpa, head.len + name.len) catch return;
+ out.appendSliceAssumeCapacity(&head);
+ out.appendSliceAssumeCapacity(name);
}
/// The daemon's registry (/sessions), its `list` answer as it gave it.
-fn daemonList(gpa: std.mem.Allocator) anyerror![]u8 {
+fn daemonList(gpa: std.mem.Allocator) error{ NoDaemon, OutOfMemory }![]u8 {
var buf: [4096]u8 = undefined;
const said = daemon.ask("list", &buf) orelse return error.NoDaemon;
return gpa.dupe(u8, said);
@@ -682,7 +684,7 @@ fn topSize(p: *Pardes, f: TopFile) u64 {
.root, .pane, .col, .screen, .new, .layout, .index, .recent, .dumps, .addons, .listeners, .sessions, .kbdin, .mousein => 0,
.tag => cols.headerText(p, null).?.len,
.README => fs.help.len,
- .status => ctl.statusText(p).len,
+ .status => if (ctl.statusText(p)) |text| text.len else |_| 0,
.look, .exec, .tagexec, .pager => ctl.resultsLen(p),
// A stream: a length would read as its end to a kernel that caches
// one (a 9ns mount's splice), and a follower's reads go past it.
@@ -836,7 +838,7 @@ fn open(p: *Pardes, req: Req, target: Target) Reply {
// pane it made, so reading it twice answers the same one and
// closing it leaves the pane alone.
.new => {
- const slot = p.freeSlot() orelse return failText(req.tag, E.NOSPC, std.fmt.bufPrint(&p.fs.ename, "pane/new: " ++ pardes.Messages.no_pane_slots, .{pardes.MAX_PANES}) catch "no space for a pane");
+ const slot = p.freeSlot() orelse return failText(req.tag, E.NOSPC, std.fmt.bufPrint(&p.fs.ename, "pane/new: " ++ pardes.Messages.no_pane_slots, .{pardes.MAX_PANES}) catch unreachable); // short
p.fs.no_pane_slot = false;
// Refused, the open's err is the one record of it (the
// one rule): no msg besides.
@@ -1080,15 +1082,15 @@ fn readFile(p: *Pardes, req: Req, target: Target) Reply {
// newline in it `\n` (events.shown).
var name_buf: [4 * 4096]u8 = undefined;
const name = events.shown(pane.nameOf(p, pn), &name_buf);
- out.print(p.gpa, "{d} {s} {d} {s} {d}\n", .{ serial, pane.kindOf(pn), @intFromBool(pane.dirtyOf(pn)), name, pane.columnOf(p, id) }) catch {};
+ out.print(p.gpa, "{d} {s} {d} {s} {d}\n", .{ serial, pane.kindOf(pn), @intFromBool(pane.dirtyOf(pn)), name, pane.columnOf(p, id) }) catch break :index Reply.fail(req.tag, E.NOMEM);
}
break :index stagedReply(p, req);
},
- .status => window(p, req, ctl.statusText(p)),
+ .status => window(p, req, ctl.statusText(p) catch return Reply.fail(req.tag, E.NOMEM)),
.look, .exec, .tagexec, .pager => ctl.readResults(p, req),
.log => events.readLog(p, req),
.screen => screen.readSnapshot(p, req, null),
- .listeners => window(p, req, screen.listenersText(p)),
+ .listeners => window(p, req, screen.listenersText(p) catch return Reply.fail(req.tag, E.NOMEM)),
.sessions => sessions: {
if (comptime !daemon.supported) break :sessions stagedReply(p, req);
// Out of the turn: the daemon answers within 2 s, or not at all.