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.
develop
Alexander Gavrilov 2012-06-16 17:09:58 +04:00
parent db91850464
commit 927ce6ce5a
2 changed files with 2 additions and 2 deletions

@ -1028,7 +1028,7 @@ static void *checkaddr(lua_State *L, int idx, bool allow_null = false)
if (lua_isnil(L, idx)) if (lua_isnil(L, idx))
rv = NULL; rv = NULL;
else if (lua_type(L, idx) == LUA_TNUMBER) else if (lua_type(L, idx) == LUA_TNUMBER)
rv = (void*)lua_tointeger(L, idx); rv = (void*)lua_tounsigned(L, idx);
else else
rv = Lua::CheckDFObject(L, NULL, idx); rv = Lua::CheckDFObject(L, NULL, idx);
if (!rv && !allow_null) if (!rv && !allow_null)

@ -715,7 +715,7 @@ static int meta_reinterpret_cast(lua_State *state)
if (lua_isnil(state, 2)) if (lua_isnil(state, 2))
ptr = NULL; ptr = NULL;
else if (lua_isnumber(state, 2)) else if (lua_isnumber(state, 2))
ptr = (void*)lua_tointeger(state, 2); ptr = (void*)lua_tounsigned(state, 2);
else else
{ {
ptr = get_object_internal(state, NULL, 2, false, true); ptr = get_object_internal(state, NULL, 2, false, true);