Skip to content

Commit

Permalink
Fix #2253: crash when accessing out-of-range attack from Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
jyrkive committed Nov 30, 2017
1 parent dcd93bb commit 6cd2a9b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/scripting/lua_unit_attacks.cpp
Expand Up @@ -49,14 +49,22 @@ void push_unit_attacks_table(lua_State* L, int idx)

void luaW_pushweapon(lua_State* L, attack_ptr weapon)
{
new(L) attack_ref(weapon);
luaL_setmetatable(L, uattackKey);
if(weapon != nullptr) {
new(L) attack_ref(weapon);
luaL_setmetatable(L, uattackKey);
} else {
lua_pushnil(L);
}
}

void luaW_pushweapon(lua_State* L, const_attack_ptr weapon)
{
new(L) attack_ref(weapon);
luaL_setmetatable(L, uattackKey);
if(weapon != nullptr) {
new(L) attack_ref(weapon);
luaL_setmetatable(L, uattackKey);
} else {
lua_pushnil(L);
}
}

static attack_ref& luaW_checkweapon_ref(lua_State* L, int idx)
Expand Down

0 comments on commit 6cd2a9b

Please sign in to comment.