zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit eac2bbfec9f99c27a886f4842cb9ca42584607f3 (tree)
parent 1872c85ac25146036119387d1f376e2cba3ff7be
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon,  8 Sep 2025 18:18:27 -0700

std.Io.Writer.writeSliceEndian: add compile error

check when an auto-layout struct is attempted to be memory reinterpreted
and written out. it would be writing undefined memory

Diffstat:
Mlib/std/Io/Writer.zig | 5+++++
1 file changed, 5 insertions(+), 0 deletions(-)

diff --git a/lib/std/Io/Writer.zig b/lib/std/Io/Writer.zig @@ -865,6 +865,11 @@ pub inline fn writeSliceEndian( slice: []const Elem, endian: std.builtin.Endian, ) Error!void { + switch (@typeInfo(Elem)) { + .@"struct" => |info| comptime assert(info.layout != .auto), + .int, .@"enum" => {}, + else => @compileError("ill-defined memory layout"), + } if (native_endian == endian) { return writeAll(w, @ptrCast(slice)); } else {