From 4839c4b037d401393bbc87143d663e115c71242e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 12:14:58 -0300 Subject: idioms #2, formats that cannot overflow say so: a bufPrint or a fixed writer whose buffer provably holds the text (numbers, a 128-byte name, a short phrase) is catch unreachable with its reason, not a catch "" or a stand-in sentence nobody can reach, and dump.check takes its 256-byte why as such Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/dump.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/dump.zig') diff --git a/src/dump.zig b/src/dump.zig index ba159325..82b1410f 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -247,14 +247,14 @@ fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 /// Whether `bytes` are a dump a Restore could read, saying nothing: a /// Restore asks before it warns about unsaved text or replaces anything. /// Why not is left in `why`, ended by a 0. -pub fn check(gpa: std.mem.Allocator, bytes: []const u8, why: []u8) !void { +pub fn check(gpa: std.mem.Allocator, bytes: []const u8, why: *[256]u8) !void { if (pardes.Db.isImage(bytes)) { const r = pardes.Db.Read.open(gpa, bytes, null) catch |err| { const said = std.fmt.bufPrint(why[0 .. why.len - 1], "{s}", .{switch (err) { error.NoDump => "it holds no dump", error.OutOfMemory => "out of memory", else => "it is no dump of pardes's", - }}) catch ""; + }}) catch unreachable; // a short phrase 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: []u8) !void { error.BadDump => "it does not begin as one", error.EndOfDump => "it is cut short", else => @errorName(err), - }}) catch ""; + }}) catch unreachable; // a short phrase or an error's name fits 255 why[said.len] = 0; return err; }; -- cgit v1.3