diff --git a/src/user.zig b/src/user.zig index 692b62a..da41488 100644 --- a/src/user.zig +++ b/src/user.zig @@ -21,11 +21,9 @@ pub const User = struct { }; pub const PackedUser = struct { - // TODO: use @bitSizeOf(Inner)/8: - //const InnerSize = @divExact(@bitSizeOf(Inner), 8); const shellIndexFnType = fn ([]const u8) ?u6; - const InnerSize = @sizeOf(Inner); + const InnerSize = @divExact(@bitSizeOf(Inner), 8); const Inner = packed struct { uid: u32, gid: u32, @@ -96,6 +94,7 @@ pub const PackedUser = struct { pub fn fromBytes(bytes: []const u8) PackedUser { const inner = std.mem.bytesAsValue( PackedUser, + // https://github.com/ziglang/zig/issues/10958 bytes[0..@sizeOf(Inner)][0..@sizeOf(Inner)], ); @@ -123,8 +122,10 @@ pub const PackedUser = struct { // packTo packs the User record and copies it to the given byte slice. The // slice must have at least maxRecordSize() bytes available. - pub fn packTo(buf1: *[]u8, user: User, shellIndexFn: shellIndexFnType) error{InvalidRecord}!void { - var buf = buf1.*; + pub fn packTo(bufPtr: *[]u8, user: User, shellIndexFn: shellIndexFnType) error{InvalidRecord}!void { + // function arguments are consts. We need to mutate the underlying + // slice, so passing it via pointer instead. + var buf = bufPtr.*; const bufStart = @ptrToInt(buf.ptr); const home_len = try downCast(u6, user.home.len - 1);