aboutsummaryrefslogtreecommitdiff
path: root/src/install/padding_checker.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/install/padding_checker.zig')
-rw-r--r--src/install/padding_checker.zig17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/install/padding_checker.zig b/src/install/padding_checker.zig
index 1d9405a43..52d343b4f 100644
--- a/src/install/padding_checker.zig
+++ b/src/install/padding_checker.zig
@@ -55,7 +55,6 @@ pub fn assertNoUninitializedPadding(comptime T: type) void {
// if (info.layout != .Extern) {
// @compileError("assertNoUninitializedPadding(" ++ @typeName(T) ++ ") expects an extern struct type, got a struct of layout '" ++ @tagName(info.layout) ++ "'");
// }
- var i = 0;
for (info.fields) |field| {
const fieldInfo = @typeInfo(field.type);
switch (fieldInfo) {
@@ -69,9 +68,12 @@ pub fn assertNoUninitializedPadding(comptime T: type) void {
else => {},
}
}
+
if (info_ == .Union) {
return;
}
+
+ var i = 0;
for (info.fields, 0..) |field, j| {
const offset = @offsetOf(T, field.name);
if (offset != i) {
@@ -90,4 +92,17 @@ pub fn assertNoUninitializedPadding(comptime T: type) void {
}
i = offset + @sizeOf(field.type);
}
+
+ if (i != @sizeOf(T)) {
+ @compileError(std.fmt.comptimePrint(
+ \\Expected no possibly uninitialized bytes of memory in '{s}', but found a {d} byte gap at the end of the struct. This can be fixed by adding a padding field to the struct like `padding: [{d}]u8 = .{{0}} ** {d},` between these fields. For more information, look at `padding_checker.zig`
+ ,
+ .{
+ @typeName(T),
+ @sizeOf(T) - i,
+ @sizeOf(T) - i,
+ @sizeOf(T) - i,
+ },
+ ));
+ }
}