From cdb3efbf60238fa3cf079db81bd5c5602104580d Mon Sep 17 00:00:00 2001 From: bangbangsheshotmedown Date: Mon, 28 Oct 2024 15:46:27 +0000 Subject: [PATCH 1/4] fmt: handle printing sentinel terminated arrays --- lib/std/fmt.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 123122fd560e..df08dcf46873 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -664,6 +664,10 @@ pub fn formatType( if (max_depth == 0) { return writer.writeAll("{ ... }"); } + if (info.sentinel) |s| { + const index = std.mem.indexOfSentinel(info.child, @as(*info.child, @constCast(@ptrCast(s))).*, value[0..]); + return formatBuf(value[0..index], options, writer); + } if (actual_fmt[0] == 's' and info.child == u8) { return formatBuf(&value, options, writer); } From 7e87c4e7c54d40d3c0749b9404393e09d7e9c2a9 Mon Sep 17 00:00:00 2001 From: bangbangsheshotmedown Date: Mon, 28 Oct 2024 16:54:49 +0000 Subject: [PATCH 2/4] simplify --- lib/std/fmt.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index df08dcf46873..9d9d9ae2613b 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -665,7 +665,7 @@ pub fn formatType( return writer.writeAll("{ ... }"); } if (info.sentinel) |s| { - const index = std.mem.indexOfSentinel(info.child, @as(*info.child, @constCast(@ptrCast(s))).*, value[0..]); + const index = std.mem.indexOfSentinel(info.child, @as(*const info.child, @ptrCast(s)).*, value[0..]); return formatBuf(value[0..index], options, writer); } if (actual_fmt[0] == 's' and info.child == u8) { From 846a60632b90dd415d172fed43804114a2c3d296 Mon Sep 17 00:00:00 2001 From: bangbangsheshotmedown Date: Wed, 29 Jan 2025 20:21:41 +0100 Subject: [PATCH 3/4] Use new function --- lib/std/fmt.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 5127f690b2a9..8e55161357bc 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -665,7 +665,7 @@ pub fn formatType( return writer.writeAll("{ ... }"); } if (info.sentinel) |s| { - const index = std.mem.indexOfSentinel(info.child, @as(*const info.child, @ptrCast(s)).*, value[0..]); + const index = std.mem.indexOfSentinel(info.child, s, value[0..]); return formatBuf(value[0..index], options, writer); } if (actual_fmt[0] == 's' and info.child == u8) { From fd437159832e4088997e7f85c88cf7786751e4d6 Mon Sep 17 00:00:00 2001 From: bangbangsheshotmedown Date: Thu, 30 Jan 2025 07:50:24 +0100 Subject: [PATCH 4/4] Missing parenthesis --- lib/std/fmt.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 8e55161357bc..010e50e05ef9 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -664,7 +664,7 @@ pub fn formatType( if (max_depth == 0) { return writer.writeAll("{ ... }"); } - if (info.sentinel) |s| { + if (info.sentinel()) |s| { const index = std.mem.indexOfSentinel(info.child, s, value[0..]); return formatBuf(value[0..index], options, writer); }