From ee79eb426e658dc7b71a29273b838a00a21780cc Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Tue, 28 Feb 2017 16:26:22 -0500 Subject: [PATCH] Fix some invalid Lua stack accesses in [animate_unit] --- src/scripting/game_lua_kernel.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index 610a307d996b..d0361f9ac8eb 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -374,10 +374,10 @@ static int impl_add_animation(lua_State* L) if(lua_isnumber(L, -1)) { v1 = lua_tonumber(L, -1); } else if(lua_istable(L, -1)) { - lua_rawgeti(L, 1, 1); + lua_rawgeti(L, -1, 1); v1 = lua_tonumber(L, -1); lua_pop(L, 1); - lua_rawgeti(L, 1, 2); + lua_rawgeti(L, -1, 2); v2 = lua_tonumber(L, -1); lua_pop(L, 2); } else if(!lua_isnoneornil(L, -1)) { @@ -403,9 +403,10 @@ static int impl_add_animation(lua_State* L) lua_getfield(L, 5, "color"); if(lua_istable(L, -1) && lua_rawlen(L, -1) == 3) { - lua_rawgeti(L, 1, 1); // red @ -3 - lua_rawgeti(L, 1, 2); // green @ -2 - lua_rawgeti(L, 1, 3); // blue @ -1 + int idx = lua_absindex(L, -1); + lua_rawgeti(L, idx, 1); // red @ -3 + lua_rawgeti(L, idx, 2); // green @ -2 + lua_rawgeti(L, idx, 3); // blue @ -1 color = color_t(lua_tonumber(L, -3), lua_tonumber(L, -2), lua_tonumber(L, -1)); lua_pop(L, 3); } else if(!lua_isnoneornil(L, -1)) {