From 76eedec62a0b34209efd51696c46c4a530952da6 Mon Sep 17 00:00:00 2001 From: William Venner Date: Thu, 10 Feb 2022 20:10:21 +0000 Subject: [PATCH] Add alignment check for userdata --- gmod/src/lua/lua_state.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gmod/src/lua/lua_state.rs b/gmod/src/lua/lua_state.rs index 0071b94..5a18173 100644 --- a/gmod/src/lua/lua_state.rs +++ b/gmod/src/lua/lua_state.rs @@ -576,6 +576,8 @@ impl LuaState { let ptr = (LUA_SHARED.lua_newuserdata)(*self, std::mem::size_of::()) as *mut T; + debug_assert_eq!(ptr as usize % std::mem::align_of::(), 0, "Lua userdata is unaligned!"); + if has_metatable { self.push_value(-2); self.set_metatable(-2);