add some guard rails w.r.t. padding

This commit is contained in:
Motiejus Jakštys 2022-02-21 13:53:52 +02:00 committed by Motiejus Jakštys
parent f77d94e624
commit ab0562950c

View File

@ -199,8 +199,19 @@ pub const UserReader = struct {
const testing = std.testing; const testing = std.testing;
test "PackedUser is byte-aligned" { test "PackedUser alignment" {
// byte-aligned
try testing.expectEqual(0, @rem(@bitSizeOf(PackedUser), 8)); 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 { fn testShellIndex(shell: []const u8) ?u6 {