mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 21:08:36 +00:00
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
This commit is contained in:
parent
1872c85ac2
commit
eac2bbfec9
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user