From 1ca2deca33e5ee489e12bd71a34ec3e4a2e1255f Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 26 Nov 2020 15:43:28 +0100 Subject: [PATCH] std: Disable the special casing of {} for u8 slices/arrays Unless {s} is specified the contents won't be treated as a string. --- lib/std/fmt.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 7adee00928..54d96168e2 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -504,7 +504,9 @@ pub fn formatType( .One => switch (@typeInfo(ptr_info.child)) { .Array => |info| { if (info.child == u8) { - return formatText(value, fmt, options, writer); + if (fmt.len > 0 and comptime mem.indexOfScalar(u8, "sxXeEzZ", fmt[0]) != null) { + return formatText(value, fmt, options, writer); + } } return format(writer, "{s}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) }); }, @@ -529,7 +531,7 @@ pub fn formatType( return writer.writeAll("{ ... }"); } if (ptr_info.child == u8) { - if (fmt.len == 0 or comptime mem.indexOfScalar(u8, "sxXeEzZ", fmt[0]) != null) { + if (fmt.len > 0 and comptime mem.indexOfScalar(u8, "sxXeEzZ", fmt[0]) != null) { return formatText(value, fmt, options, writer); } }