From 2a74c691eb7684e22cc52d8ff7619bcb4c9acc76 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 20 Jul 2023 23:25:47 +0200 Subject: [PATCH] Enforce alignment of Array.slice() at compile time --- src/common_core.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common_core.zig b/src/common_core.zig index fc35459..4c2d128 100644 --- a/src/common_core.zig +++ b/src/common_core.zig @@ -32,10 +32,10 @@ pub const Array = extern struct { }; } - pub fn slice(array: Array, comptime T: type) []T { + pub fn slice(array: Array, comptime T: type) []align(4) T { const data = array.data orelse return &[0]T{}; // The wire protocol/libwayland only guarantee 32-bit word alignment. - const ptr: [*]T = @ptrCast(@alignCast(data)); + const ptr: [*]align(4) T = @ptrCast(@alignCast(data)); return ptr[0..@divExact(array.size, @sizeOf(T))]; } };