From bbcebf80c45e0182bf8ff6adc2336afc4bc4af51 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 05:10:28 -0300 Subject: walk: an optional slice or pointer loads through a local, not into an optional set to an undefined payload: a slice's null is its address, so that optional was undefined and ReleaseSafe's optimizer took it as null; a command pane's `?[]u8` command read one byte long, every field after it out of step, and Restore of a session with a command pane in it said "end of dump" (Debug's 0xAA filler and ReleaseFast read it right); a test of an optional slice and the field after it aborts in ReleaseSafe without it Co-Authored-By: Claude Opus 5.5 --- src/walk.zig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/walk.zig') diff --git a/src/walk.zig b/src/walk.zig index d0d20e8a..3556ce88 100644 --- a/src/walk.zig +++ b/src/walk.zig @@ -1332,6 +1332,17 @@ pub fn Load(comptime roots: []const type) type { out.* = if (comptime C == std.mem.Allocator) l.gpa else null; return; } + // A slice's or a pointer's null is its address: set to + // an undefined payload, the optional itself is undefined, + // and ReleaseSafe's optimizer read it as null (a pane's + // `?[]u8` command one byte long, every field after it out + // of step). Read through a local and set it from that. + if (comptime @typeInfo(C) == .pointer) { + var payload: C = undefined; + try l.value(C, s.child, &payload); + out.* = payload; + return; + } out.* = @as(C, undefined); try l.fresh(C, &out.*.?); l.value(C, s.child, &out.*.?) catch |err| { @@ -1626,6 +1637,18 @@ pub fn load(comptime T: type, gpa: std.mem.Allocator, bytes: []const u8, notes: return v; } +test "an optional slice comes back, and the fields after it" { + const S = struct { before: u32 = 0, command: ?[]u8 = null, after: u32 = 0 }; + var text = "sleep 30".*; + const bytes = try save(S, std.testing.allocator, &.{ .before = 1, .command = &text, .after = 2 }); + defer std.testing.allocator.free(bytes); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const back = try load(S, arena.allocator(), bytes, null); + try std.testing.expectEqualStrings("sleep 30", back.command.?); + try std.testing.expectEqual(2, back.after); +} + test "a dump comes back whole: shared things shared, lists and runs as long as they were" { const gpa = std.testing.allocator; const Leaf = struct { n: u21, name: []const u8 }; -- cgit v1.3