From 292879d0fbfb4761500e3e843f65c39e226e3184 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 4 Feb 2024 08:51:45 +0400 Subject: [PATCH] Address Coverity Scan complaints left --- apps/openmw/mwdialogue/filter.cpp | 10 ++++++++-- apps/openmw/mwlua/animationbindings.cpp | 9 +++++---- apps/openmw/mwlua/itemdata.cpp | 4 ++-- apps/openmw/mwlua/luamanagerimp.cpp | 2 +- apps/openmw/mwlua/postprocessingbindings.cpp | 2 +- apps/openmw/mwlua/types/actor.cpp | 3 ++- apps/openmw/mwlua/types/player.cpp | 2 +- apps/openmw/mwlua/uibindings.cpp | 4 ++-- 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 899acf603e..8b67ea28b3 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -375,12 +375,18 @@ int MWDialogue::Filter::getSelectStructInteger(const SelectWrapper& select) cons return mChoice; case SelectWrapper::Function_AiSetting: + { + int argument = select.getArgument(); + if (argument < 0 || argument > 3) + { + throw std::runtime_error("AiSetting index is out of range"); + } return mActor.getClass() .getCreatureStats(mActor) - .getAiSetting((MWMechanics::AiSetting)select.getArgument()) + .getAiSetting(static_cast(argument)) .getModified(false); - + } case SelectWrapper::Function_PcAttribute: { ESM::RefId attribute = ESM::Attribute::indexToRefId(select.getArgument()); diff --git a/apps/openmw/mwlua/animationbindings.cpp b/apps/openmw/mwlua/animationbindings.cpp index a1f472908c..d024c41307 100644 --- a/apps/openmw/mwlua/animationbindings.cpp +++ b/apps/openmw/mwlua/animationbindings.cpp @@ -344,18 +344,19 @@ namespace MWLua [world, context](const sol::object& staticOrID, const osg::Vec3f& worldPos) { auto model = getStaticModelOrThrow(staticOrID); context.mLuaManager->addAction( - [world, model, worldPos]() { world->spawnEffect(model, "", worldPos); }, "openmw.vfx.spawn"); + [world, model = std::move(model), worldPos]() { world->spawnEffect(model, "", worldPos); }, + "openmw.vfx.spawn"); }, [world, context](const sol::object& staticOrID, const osg::Vec3f& worldPos, const sol::table& options) { auto model = getStaticModelOrThrow(staticOrID); bool magicVfx = options.get_or("mwMagicVfx", true); - std::string textureOverride = options.get_or("particleTextureOverride", ""); + std::string texture = options.get_or("particleTextureOverride", ""); float scale = options.get_or("scale", 1.f); context.mLuaManager->addAction( - [world, model, textureOverride, worldPos, scale, magicVfx]() { - world->spawnEffect(model, textureOverride, worldPos, scale, magicVfx); + [world, model = std::move(model), texture = std::move(texture), worldPos, scale, magicVfx]() { + world->spawnEffect(model, texture, worldPos, scale, magicVfx); }, "openmw.vfx.spawn"); }); diff --git a/apps/openmw/mwlua/itemdata.cpp b/apps/openmw/mwlua/itemdata.cpp index 6dea2360e7..d7ced755ea 100644 --- a/apps/openmw/mwlua/itemdata.cpp +++ b/apps/openmw/mwlua/itemdata.cpp @@ -42,7 +42,7 @@ namespace MWLua ObjectVariant mObject; public: - ItemData(ObjectVariant object) + ItemData(const ObjectVariant& object) : mObject(object) { } @@ -116,7 +116,7 @@ namespace MWLua item["itemData"] = [](const sol::object& object) -> sol::optional { ObjectVariant o(object); if (o.ptr().getClass().isItem(o.ptr()) || o.ptr().mRef->getType() == ESM::REC_LIGH) - return ItemData(std::move(o)); + return ItemData(o); return {}; }; diff --git a/apps/openmw/mwlua/luamanagerimp.cpp b/apps/openmw/mwlua/luamanagerimp.cpp index d4366cac50..8fde31ef85 100644 --- a/apps/openmw/mwlua/luamanagerimp.cpp +++ b/apps/openmw/mwlua/luamanagerimp.cpp @@ -643,7 +643,7 @@ namespace MWLua scripts->setSavedDataDeserializer(mLocalSerializer.get()); ESM::LuaScripts data; scripts->save(data); - localData[id] = data; + localData[id] = std::move(data); } mMenuScripts.removeAllScripts(); diff --git a/apps/openmw/mwlua/postprocessingbindings.cpp b/apps/openmw/mwlua/postprocessingbindings.cpp index 5ce37d13da..74359e3a4b 100644 --- a/apps/openmw/mwlua/postprocessingbindings.cpp +++ b/apps/openmw/mwlua/postprocessingbindings.cpp @@ -85,7 +85,7 @@ namespace MWLua } context.mLuaManager->addAction( - [=] { + [shader, name, values = std::move(values)] { MWBase::Environment::get().getWorld()->getPostProcessor()->setUniform(shader.mShader, name, values); }, "SetUniformShaderAction"); diff --git a/apps/openmw/mwlua/types/actor.cpp b/apps/openmw/mwlua/types/actor.cpp index 473b0d3301..4fda04e7c5 100644 --- a/apps/openmw/mwlua/types/actor.cpp +++ b/apps/openmw/mwlua/types/actor.cpp @@ -274,7 +274,8 @@ namespace MWLua { ei = LuaUtil::cast(item); } - context.mLuaManager->addAction([obj = Object(ptr), ei = ei] { setSelectedEnchantedItem(obj.ptr(), ei); }, + context.mLuaManager->addAction( + [obj = Object(ptr), ei = std::move(ei)] { setSelectedEnchantedItem(obj.ptr(), ei); }, "setSelectedEnchantedItemAction"); }; diff --git a/apps/openmw/mwlua/types/player.cpp b/apps/openmw/mwlua/types/player.cpp index 812296daf8..d2a9c5d920 100644 --- a/apps/openmw/mwlua/types/player.cpp +++ b/apps/openmw/mwlua/types/player.cpp @@ -117,7 +117,7 @@ namespace MWLua // The journal mwscript function has a try function here, we will make the lua function throw an // error. However, the addAction will cause it to error outside of this function. context.mLuaManager->addAction( - [actor, q, stage] { + [actor = std::move(actor), q, stage] { MWWorld::Ptr actorPtr; if (actor) actorPtr = actor->ptr(); diff --git a/apps/openmw/mwlua/uibindings.cpp b/apps/openmw/mwlua/uibindings.cpp index 6b1dcfef51..b5bd30fbe6 100644 --- a/apps/openmw/mwlua/uibindings.cpp +++ b/apps/openmw/mwlua/uibindings.cpp @@ -241,7 +241,7 @@ namespace MWLua for (unsigned i = 0; i < newStack.size(); ++i) newStack[i] = nameToMode.at(LuaUtil::cast(modes[i + 1])); luaManager->addAction( - [windowManager, newStack, arg]() { + [windowManager, newStack = std::move(newStack), arg]() { MWWorld::Ptr ptr; if (arg.has_value()) ptr = arg->ptr(); @@ -319,7 +319,7 @@ namespace MWLua }; auto uiLayer = context.mLua->sol().new_usertype("UiLayer"); - uiLayer["name"] = sol::readonly_property([](LuaUi::Layer& self) { return self.name(); }); + uiLayer["name"] = sol::readonly_property([](LuaUi::Layer& self) -> std::string_view { return self.name(); }); uiLayer["size"] = sol::readonly_property([](LuaUi::Layer& self) { return self.size(); }); uiLayer[sol::meta_function::to_string] = [](LuaUi::Layer& self) { return Misc::StringUtils::format("UiLayer(%s)", self.name()); };