mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:24:33 +01:00
std.Io.Reader.takeStruct: dont assert buffer capacity is sizeOf(T)
This commit is contained in:
parent
97986184ca
commit
5e9c484745
1 changed files with 2 additions and 3 deletions
|
|
@ -1192,8 +1192,6 @@ pub fn peekStructPointer(r: *Reader, comptime T: type) Error!*align(1) T {
|
|||
return @ptrCast(try r.peekArray(@sizeOf(T)));
|
||||
}
|
||||
|
||||
/// Asserts the buffer was initialized with a capacity at least `@sizeOf(T)`.
|
||||
///
|
||||
/// This function is inline to avoid referencing `std.mem.byteSwapAllFields`
|
||||
/// when `endian` is comptime-known and matches the host endianness.
|
||||
///
|
||||
|
|
@ -1205,7 +1203,8 @@ pub inline fn takeStruct(r: *Reader, comptime T: type, endian: std.builtin.Endia
|
|||
.@"struct" => |info| switch (info.layout) {
|
||||
.auto => @compileError("ill-defined memory layout"),
|
||||
.@"extern" => {
|
||||
var res = (try r.takeStructPointer(T)).*;
|
||||
var res: T = undefined;
|
||||
try r.readSliceAll(std.mem.asBytes(&res));
|
||||
if (native_endian != endian) std.mem.byteSwapAllFields(T, &res);
|
||||
return res;
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue