summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 05:10:28 -0300
committerGabriel Schneider <[email protected]>2026-10-30 05:10:28 -0300
commitbbcebf80c45e0182bf8ff6adc2336afc4bc4af51 (patch)
treed97a49ca0cf83bba5a1c964a2f30fae0df136be4
parentab0946311085f6fa337162302ea2f9f25b1877e2 (diff)
downloadpardes-bbcebf80c45e0182bf8ff6adc2336afc4bc4af51.tar.gz
pardes-bbcebf80c45e0182bf8ff6adc2336afc4bc4af51.zip
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 <[email protected]>
-rw-r--r--src/walk.zig23
1 files changed, 23 insertions, 0 deletions
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 };