Skip to content

Commit

Permalink
Fix std::unordered_map<std::string, std::string> parsing (#3246)
Browse files Browse the repository at this point in the history
  • Loading branch information
tederis authored Nov 20, 2023
1 parent f32824a commit 0055924
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,16 @@ struct CLuaFunctionParserBase
}

int i = -2;
auto k = PopUnsafe<key_t>(L, i);

// When key_t is a string and the actual type of a key is number Lua will conduct an implicit value change
// that can confuse lua_next and lead to a crash. To fix it we can copy a key in order to save an original key
// that will be used during the next lua_next invocation.
lua_pushvalue(L, i);

auto v = PopUnsafe<value_t>(L, i);
auto k = PopUnsafe<key_t>(L, i);
map.emplace(std::move(k), std::move(v));
lua_pop(L, 1); // drop value, keep key for lua_next
lua_pop(L, 2); // drop values(key copy and value), keep original key for lua_next
}
++index;
return map;
Expand Down

0 comments on commit 0055924

Please sign in to comment.