1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-29 12:20:41 +00:00

Fix memory safety of actions/triggers iteration

This commit is contained in:
uramer 2024-08-07 19:20:12 +02:00
parent 2df8c13525
commit ab628ea12a

View File

@ -71,9 +71,10 @@ namespace MWLua
= [](LuaUtil::InputAction::Registry& registry, std::string_view key) { return registry[key]; }; = [](LuaUtil::InputAction::Registry& registry, std::string_view key) { return registry[key]; };
{ {
auto pairs = [](LuaUtil::InputAction::Registry& registry) { auto pairs = [](LuaUtil::InputAction::Registry& registry) {
auto next = [](LuaUtil::InputAction::Registry& registry, std::string_view key) auto next
-> sol::optional<std::tuple<std::string_view, LuaUtil::InputAction::Info>> { = [](LuaUtil::InputAction::Registry& registry,
std::optional<std::string_view> nextKey(registry.nextKey(key)); std::string_view key) -> sol::optional<std::tuple<std::string, LuaUtil::InputAction::Info>> {
std::optional<std::string> nextKey(registry.nextKey(key));
if (!nextKey.has_value()) if (!nextKey.has_value())
return sol::nullopt; return sol::nullopt;
else else
@ -102,9 +103,10 @@ namespace MWLua
= [](LuaUtil::InputTrigger::Registry& registry, std::string_view key) { return registry[key]; }; = [](LuaUtil::InputTrigger::Registry& registry, std::string_view key) { return registry[key]; };
{ {
auto pairs = [](LuaUtil::InputTrigger::Registry& registry) { auto pairs = [](LuaUtil::InputTrigger::Registry& registry) {
auto next = [](LuaUtil::InputTrigger::Registry& registry, std::string_view key) auto next
-> sol::optional<std::tuple<std::string_view, LuaUtil::InputTrigger::Info>> { = [](LuaUtil::InputTrigger::Registry& registry,
std::optional<std::string_view> nextKey(registry.nextKey(key)); std::string_view key) -> sol::optional<std::tuple<std::string, LuaUtil::InputTrigger::Info>> {
std::optional<std::string> nextKey(registry.nextKey(key));
if (!nextKey.has_value()) if (!nextKey.has_value())
return sol::nullopt; return sol::nullopt;
else else