From 788900c35c99361e4ab0e2b5dd38cfa0737700d7 Mon Sep 17 00:00:00 2001 From: "J.C. Moyer" Date: Fri, 30 Oct 2020 23:48:41 -0400 Subject: [PATCH] Add test for null terminated slices with embedded null bytes --- lib/std/fmt.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index f8401521d4..bcc22502f1 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -1385,6 +1385,10 @@ test "slice" { const value = @intToPtr([*]align(1) const []const u8, 0xdeadbeef)[runtime_zero..runtime_zero]; try testFmt("slice: []const u8@deadbeef\n", "slice: {}\n", .{value}); } + { + const null_term_slice: [:0]const u8 = "\x00hello\x00"; + try testFmt("buf: \x00hello\x00\n", "buf: {s}\n", .{null_term_slice}); + } try testFmt("buf: Test\n", "buf: {s:5}\n", .{"Test"}); try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", .{"Test"});