1
Fork 0

add some guard rails w.r.t. padding

main
Motiejus Jakštys 2022-02-21 13:53:52 +02:00 committed by Motiejus Jakštys
parent f77d94e624
commit ab0562950c
1 changed files with 12 additions and 1 deletions

View File

@ -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 {