authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-01-15 16:39:34+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-01-15 21:13:51+00:00
log77273103a8f9895ceab28287dffcf4d4c6fcb91b
treefa87925f01b5b338fb2d32dc1e21847d68d55233
parent4b910e525d97276c64e98832663f0acfe8ff5cfb

print_value: fix crash on undefined slice ptr

Resolves: #22418

1 files changed, 16 insertions(+), 9 deletions(-)

src/print_value.zig+16-9
...@@ -130,16 +130,23 @@ pub fn print(...@@ -130,16 +130,23 @@ pub fn print(
130 inline else => |x| try writer.print("{d}", .{@as(f64, @floatCast(x))}),130 inline else => |x| try writer.print("{d}", .{@as(f64, @floatCast(x))}),
131 },131 },
132 .slice => |slice| {132 .slice => |slice| {
133 const print_contents = switch (ip.getBackingAddrTag(slice.ptr).?) {133 if (ip.isUndef(slice.ptr)) {
134 .field, .arr_elem, .eu_payload, .opt_payload => unreachable,134 if (slice.len == .zero_usize) {
135 .uav, .comptime_alloc, .comptime_field => true,135 return writer.writeAll("&.{}");
136 .nav, .int => false,136 }
137 };137 try print(.fromInterned(slice.ptr), writer, level - 1, pt, opt_sema);
138 if (print_contents) {138 } else {
139 // TODO: eventually we want to load the slice as an array with `sema`, but that's139 const print_contents = switch (ip.getBackingAddrTag(slice.ptr).?) {
140 // currently not possible without e.g. triggering compile errors.140 .field, .arr_elem, .eu_payload, .opt_payload => unreachable,
141 .uav, .comptime_alloc, .comptime_field => true,
142 .nav, .int => false,
143 };
144 if (print_contents) {
145 // TODO: eventually we want to load the slice as an array with `sema`, but that's
146 // currently not possible without e.g. triggering compile errors.
147 }
148 try printPtr(Value.fromInterned(slice.ptr), null, writer, level, pt, opt_sema);
141 }149 }
142 try printPtr(Value.fromInterned(slice.ptr), null, writer, level, pt, opt_sema);
143 try writer.writeAll("[0..");150 try writer.writeAll("[0..");
144 if (level == 0) {151 if (level == 0) {
145 try writer.writeAll("(...)");152 try writer.writeAll("(...)");