From e9b48e35c0b36c0a9ba50bd0b844aee37deeb2f9 Mon Sep 17 00:00:00 2001 From: uramer Date: Tue, 2 Jan 2024 13:54:02 +0100 Subject: [PATCH] Coverity defects --- apps/openmw/mwlua/inputbindings.cpp | 8 ++++---- components/lua/inputactions.cpp | 4 ++-- components/lua/inputactions.hpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwlua/inputbindings.cpp b/apps/openmw/mwlua/inputbindings.cpp index 8763dce28d..33b19f3b4d 100644 --- a/apps/openmw/mwlua/inputbindings.cpp +++ b/apps/openmw/mwlua/inputbindings.cpp @@ -76,7 +76,7 @@ namespace MWLua inputActions[sol::meta_function::pairs] = pairs; } - auto actionInfo = context.mLua->sol().new_usertype("ActionInfo", "key", + context.mLua->sol().new_usertype("ActionInfo", "key", sol::property([](const LuaUtil::InputAction::Info& info) { return info.mKey; }), "name", sol::property([](const LuaUtil::InputAction::Info& info) { return info.mName; }), "description", sol::property([](const LuaUtil::InputAction::Info& info) { return info.mDescription; }), "type", @@ -102,7 +102,7 @@ namespace MWLua inputTriggers[sol::meta_function::pairs] = pairs; } - auto triggerInfo = context.mLua->sol().new_usertype("TriggerInfo", "key", + context.mLua->sol().new_usertype("TriggerInfo", "key", sol::property([](const LuaUtil::InputTrigger::Info& info) { return info.mKey; }), "name", sol::property([](const LuaUtil::InputTrigger::Info& info) { return info.mName; }), "description", sol::property([](const LuaUtil::InputTrigger::Info& info) { return info.mDescription; }), "l10n", @@ -127,7 +127,7 @@ namespace MWLua parsedOptions.mName = options["name"].get(); parsedOptions.mDescription = options["description"].get(); parsedOptions.mDefaultValue = options["defaultValue"].get(); - manager->inputActions().insert(parsedOptions); + manager->inputActions().insert(std::move(parsedOptions)); }; api["bindAction"] = [manager = context.mLuaManager]( std::string_view key, const sol::table& callback, sol::table dependencies) { @@ -164,7 +164,7 @@ namespace MWLua parsedOptions.mL10n = options["l10n"].get(); parsedOptions.mName = options["name"].get(); parsedOptions.mDescription = options["description"].get(); - manager->inputTriggers().insert(parsedOptions); + manager->inputTriggers().insert(std::move(parsedOptions)); }; api["registerTriggerHandler"] = [manager = context.mLuaManager](std::string_view key, const sol::table& callback) { diff --git a/components/lua/inputactions.cpp b/components/lua/inputactions.cpp index 69c91921eb..7c7551ba60 100644 --- a/components/lua/inputactions.cpp +++ b/components/lua/inputactions.cpp @@ -113,7 +113,7 @@ namespace LuaUtil } } - void Registry::insert(Info info) + void Registry::insert(const Info& info) { if (mIds.find(info.mKey) != mIds.end()) throw std::domain_error(Misc::StringUtils::format("Action key \"%s\" is already in use", info.mKey)); @@ -251,7 +251,7 @@ namespace LuaUtil return it->second; } - void Registry::insert(Info info) + void Registry::insert(const Info& info) { if (mIds.find(info.mKey) != mIds.end()) throw std::domain_error(Misc::StringUtils::format("Trigger key \"%s\" is already in use", info.mKey)); diff --git a/components/lua/inputactions.hpp b/components/lua/inputactions.hpp index abc6cf73fa..d05bb71f2c 100644 --- a/components/lua/inputactions.hpp +++ b/components/lua/inputactions.hpp @@ -60,7 +60,7 @@ namespace LuaUtil::InputAction { public: using ConstIterator = std::vector::const_iterator; - void insert(Info info); + void insert(const Info& info); size_t size() const { return mKeys.size(); } std::optional firstKey() const { return mKeys.empty() ? std::nullopt : std::optional(mKeys[0]); } std::optional nextKey(std::string_view key) const; @@ -127,7 +127,7 @@ namespace LuaUtil::InputTrigger return it->first; } std::optional operator[](std::string_view key); - void insert(Info info); + void insert(const Info& info); void registerHandler(std::string_view key, const LuaUtil::Callback& callback); void activate(std::string_view key); void clear()