Skip to content

Commit

Permalink
SAPI: Fix seed parameter truncation for LuaPseudoRandom constructor
Browse files Browse the repository at this point in the history
Also fix a potential seed truncation issue on platforms where the
range of ptrdiff_t (the underlying type of lua_Integer) is too small.
  • Loading branch information
kwolekr committed Oct 26, 2015
1 parent 306b067 commit bc0318d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/script/lua_api/l_noise.cpp
Expand Up @@ -440,7 +440,7 @@ int LuaPseudoRandom::create_object(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

int seed = luaL_checknumber(L, 1);
u64 seed = luaL_checknumber(L, 1);
LuaPseudoRandom *o = new LuaPseudoRandom(seed);
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
luaL_getmetatable(L, className);
Expand Down Expand Up @@ -537,8 +537,8 @@ int LuaPcgRandom::create_object(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

lua_Integer seed = luaL_checknumber(L, 1);
LuaPcgRandom *o = lua_isnumber(L, 2) ?
u64 seed = luaL_checknumber(L, 1);
LuaPcgRandom *o = lua_isnumber(L, 2) ?
new LuaPcgRandom(seed, lua_tointeger(L, 2)) :
new LuaPcgRandom(seed);
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
Expand Down

0 comments on commit bc0318d

Please sign in to comment.