From 927ce6ce5adf019fd4f5fe18024b4f1b4c17fc20 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sat, 16 Jun 2012 17:09:58 +0400 Subject: [PATCH] Fix a problem with number to address cast for high-half addresses. If the address is out of the signed int range, lua_tointeger produces unspecified result. lua_tounsigned is guaranteed to wrap. --- library/LuaApi.cpp | 2 +- library/LuaWrapper.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 50458f119..cdfd47892 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1028,7 +1028,7 @@ static void *checkaddr(lua_State *L, int idx, bool allow_null = false) if (lua_isnil(L, idx)) rv = NULL; else if (lua_type(L, idx) == LUA_TNUMBER) - rv = (void*)lua_tointeger(L, idx); + rv = (void*)lua_tounsigned(L, idx); else rv = Lua::CheckDFObject(L, NULL, idx); if (!rv && !allow_null) diff --git a/library/LuaWrapper.cpp b/library/LuaWrapper.cpp index 7c15a27aa..9f2fc2f16 100644 --- a/library/LuaWrapper.cpp +++ b/library/LuaWrapper.cpp @@ -715,7 +715,7 @@ static int meta_reinterpret_cast(lua_State *state) if (lua_isnil(state, 2)) ptr = NULL; else if (lua_isnumber(state, 2)) - ptr = (void*)lua_tointeger(state, 2); + ptr = (void*)lua_tounsigned(state, 2); else { ptr = get_object_internal(state, NULL, 2, false, true);