diff --git a/src/user.zig b/src/user.zig index 47b3241..387fdf5 100644 --- a/src/user.zig +++ b/src/user.zig @@ -199,8 +199,19 @@ pub const UserReader = struct { const testing = std.testing; -test "PackedUser is byte-aligned" { +test "PackedUser alignment" { + // byte-aligned try testing.expectEqual(0, @rem(@bitSizeOf(PackedUser), 8)); + + const bytes = @divExact(@bitSizeOf(PackedUser), 8); + + // External padding (PackedUserAlignmentBits) must be higher or equal to + // the "internal" PackedUser alignment. By aligning PackedUser we are also + // working around https://github.com/ziglang/zig/issues/10958 ; PackedUser + // cannot be converted from/to [@bitSizeOf(PackedUser)/8]u8; + // asBytes/bytesAsValue use @sizeOf, which is larger. Now we are putting no + // more than 1, but it probably could be higher. + try testing.expect(@sizeOf(PackedUser) - bytes <= 1); } fn testShellIndex(shell: []const u8) ?u6 {