1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-28 17:09:41 +00:00

Merge branch 'more_coverity_fixes' into 'master'

More coverity fixes

See merge request OpenMW/openmw!3304
This commit is contained in:
psi29a 2023-08-03 07:15:34 +00:00
commit 4aaffa72e5
18 changed files with 100 additions and 27 deletions

View file

@ -178,11 +178,20 @@ int main(int argc, char** argv)
{
vfs = std::make_unique<VFS::Manager>();
for (const std::filesystem::path& path : archives)
if (auto archive = makeArchive(path))
vfs->addArchive(std::move(archive));
else
std::cerr << '"' << path << "\" is unsupported archive" << std::endl;
vfs->buildIndex();
{
try
{
if (auto archive = makeArchive(path))
vfs->addArchive(std::move(archive));
else
std::cerr << '"' << path << "\" is unsupported archive" << std::endl;
vfs->buildIndex();
}
catch (std::exception& e)
{
std::cerr << "ERROR, an exception has occurred: " << e.what() << std::endl;
}
}
}
// std::cout << "Reading Files" << std::endl;

View file

@ -100,6 +100,7 @@ namespace CSMPrefs
{
QWidget* widget = static_cast<QWidget*>(watched);
ShortcutMap::iterator shortcutListIt = mWidgetShortcuts.find(widget);
assert(shortcutListIt != mWidgetShortcuts.end());
// Deactivate in case events are missed
for (ShortcutList::iterator it = shortcutListIt->second.begin(); it != shortcutListIt->second.end(); ++it)

View file

@ -744,7 +744,9 @@ void CSMWorld::RefIdCollection::cloneRecord(
const ESM::RefId& origin, const ESM::RefId& destination, const CSMWorld::UniversalId::Type type)
{
std::unique_ptr<RecordBase> newRecord = mData.getRecord(mData.searchId(origin)).modifiedCopy();
mAdapters.find(type)->second->setId(*newRecord, destination.getRefIdString());
auto adapter = mAdapters.find(type);
assert(adapter != mAdapters.end());
adapter->second->setId(*newRecord, destination.getRefIdString());
mData.insertRecord(std::move(newRecord), type, destination);
}

View file

@ -429,7 +429,9 @@ void CSMWorld::RefIdData::copyTo(int index, RefIdData& target) const
{
LocalIndex localIndex = globalToLocalIndex(index);
RefIdDataContainerBase* source = mRecordContainers.find(localIndex.second)->second;
auto foundIndex = mRecordContainers.find(localIndex.second);
assert(foundIndex != mRecordContainers.end());
RefIdDataContainerBase* source = foundIndex->second;
target.insertRecord(
source->getRecord(localIndex.first).modifiedCopy(), localIndex.second, source->getId(localIndex.first));

View file

@ -129,7 +129,9 @@ CSVWidget::ModeButton* CSVWidget::SceneToolMode::getCurrent()
std::string CSVWidget::SceneToolMode::getCurrentId() const
{
return mButtons.find(mCurrent)->second;
auto currentButton = mButtons.find(mCurrent);
assert(currentButton != mButtons.end());
return currentButton->second;
}
void CSVWidget::SceneToolMode::setButton(const std::string& id)

View file

@ -354,7 +354,16 @@ namespace MWGui
const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().search(skillId);
if (!skill) // Skip unknown skills
continue;
const MWMechanics::SkillValue& stat = mSkillValues.find(skill->mId)->second;
auto skillValue = mSkillValues.find(skill->mId);
if (skillValue == mSkillValues.end())
{
Log(Debug::Error) << "Failed to update stats review window: can not find value for skill "
<< skill->mId;
continue;
}
const MWMechanics::SkillValue& stat = skillValue->second;
int base = stat.getBase();
int modified = stat.getModified();

View file

@ -151,7 +151,10 @@ namespace MWGui
MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player);
MWMechanics::Spells& spells = stats.getSpells();
spells.add(mSpellsWidgetMap.find(_sender)->second);
auto spell = mSpellsWidgetMap.find(_sender);
assert(spell != mSpellsWidgetMap.end());
spells.add(spell->second);
player.getClass().getContainerStore(player).remove(MWWorld::ContainerStore::sGoldId, price);
// add gold to NPC trading gold pool

View file

@ -10,6 +10,8 @@
#include <MyGUI_TextIterator.h>
#include <MyGUI_Window.h>
#include <components/debug/debuglog.hpp>
#include <components/esm3/loadbsgn.hpp>
#include <components/esm3/loadclas.hpp>
#include <components/esm3/loadfact.hpp>
@ -496,6 +498,13 @@ namespace MWGui
if (!skill) // Skip unknown skills
continue;
auto skillValue = mSkillValues.find(skill->mId);
if (skillValue == mSkillValues.end())
{
Log(Debug::Error) << "Failed to update stats window: can not find value for skill " << skill->mId;
continue;
}
const ESM::Attribute* attr = esmStore.get<ESM::Attribute>().find(skill->mData.mAttribute);
std::pair<MyGUI::TextBox*, MyGUI::TextBox*> widgets
@ -516,7 +525,7 @@ namespace MWGui
mSkillWidgets[mSkillWidgets.size() - 1 - i]->setUserString("Range_SkillProgress", "100");
}
setValue(skill->mId, mSkillValues.find(skill->mId)->second);
setValue(skill->mId, skillValue->second);
}
}

View file

@ -5,6 +5,7 @@
#include <extern/oics/ICSChannelListener.h>
#include <extern/oics/ICSInputControlSystem.h>
#include <components/debug/debuglog.hpp>
#include <components/files/conversion.hpp>
#include <components/sdlutil/sdlmappings.hpp>
@ -193,7 +194,14 @@ namespace MWInput
BindingsManager::~BindingsManager()
{
mInputBinder->save(Files::pathToUnicodeString(mUserFile));
try
{
mInputBinder->save(Files::pathToUnicodeString(mUserFile));
}
catch (std::exception& e)
{
Log(Debug::Error) << "Failed to save input bindings: " << e.what();
}
}
void BindingsManager::update(float dt)

View file

@ -57,6 +57,8 @@ namespace MWLua
effect.mRange = ESM::RT_Self;
effect.mArea = 0;
effect.mDuration = 0;
effect.mMagnMin = 0;
effect.mMagnMax = 0;
res[i + 1] = effect;
}
return res;

View file

@ -31,6 +31,7 @@ namespace
misc.mScript = ESM::RefId::deserializeText(scriptId);
misc.mData.mWeight = rec["weight"];
misc.mData.mValue = rec["value"];
misc.mData.mFlags = 0;
misc.mRecordFlags = 0;
return misc;
}

View file

@ -30,6 +30,7 @@ namespace
potion.mScript = ESM::RefId::deserializeText(scriptId);
potion.mData.mWeight = rec["weight"];
potion.mData.mValue = rec["value"];
potion.mData.mAutoCalc = 0;
potion.mRecordFlags = 0;
sol::table effectsTable = rec["effects"];
size_t numEffects = effectsTable.size();

View file

@ -4,6 +4,7 @@
#include <apps/openmw/profile.hpp>
#include <components/debug/debuglog.hpp>
#include <components/settings/values.hpp>
#include <osgViewer/Viewer>
@ -82,7 +83,14 @@ namespace MWLua
if (mJoinRequest)
break;
update();
try
{
update();
}
catch (std::exception& e)
{
Log(Debug::Error) << "Failed to update LuaManager: " << e.what();
}
mUpdateRequest = false;
lk.unlock();

View file

@ -6,6 +6,7 @@
#include <osg/Group>
#include <osg/PositionAttitudeTransform>
#include <components/debug/debuglog.hpp>
#include <components/esm3/loadpgrd.hpp>
#include <components/misc/coordinateconverter.hpp>
#include <components/resource/resourcesystem.hpp>
@ -36,7 +37,14 @@ namespace MWRender
{
if (mPathgridEnabled)
{
togglePathgrid();
try
{
togglePathgrid();
}
catch (std::exception& e)
{
Log(Debug::Error) << "Failed to destroy pathgrid: " << e.what();
}
}
}

View file

@ -457,6 +457,8 @@ namespace DetourNavigator
const auto offMeshConnections = mOffMeshConnectionsManager.get().get(job.mChangedTile);
assert(preparedNavMeshDataPtr != nullptr);
const UpdateNavMeshStatus status
= navMeshCacheItem.lock()->updateTile(job.mChangedTile, std::move(cachedNavMeshData),
makeNavMeshTileData(*preparedNavMeshDataPtr, offMeshConnections, job.mAgentBounds, job.mChangedTile,

View file

@ -162,15 +162,9 @@ namespace DetourNavigator
const osg::Vec3f bmin(shift.x() - halfBoundsSize, minZ, shift.y() - halfBoundsSize);
const osg::Vec3f bmax(shift.x() + halfBoundsSize, maxZ, shift.y() + halfBoundsSize);
if (width < 0)
if (size < 0)
{
Log(Debug::Warning) << context.getPrefix() << "Invalid width to init heightfield: " << width;
return false;
}
if (height < 0)
{
Log(Debug::Warning) << context.getPrefix() << "Invalid height to init heightfield: " << height;
Log(Debug::Warning) << context.getPrefix() << "Invalid size to init heightfield: " << size;
return false;
}

View file

@ -48,6 +48,11 @@ namespace ESM4
{
namespace
{
std::string getError(const std::string& header, const int errorCode, const char* msg)
{
return header + ": code " + std::to_string(errorCode) + ", " + std::string(msg != nullptr ? msg : "(null)");
}
std::u8string_view getStringsSuffix(LocalizedStringType type)
{
switch (type)
@ -78,12 +83,12 @@ namespace ESM4
stream.avail_out = decompressed.size();
if (const int ec = inflateInit(&stream); ec != Z_OK)
return "inflateInit error: " + std::to_string(ec) + " " + std::string(stream.msg);
return getError("inflateInit error", ec, stream.msg);
const std::unique_ptr<z_stream, InflateEnd> streamPtr(&stream);
if (const int ec = inflate(&stream, Z_NO_FLUSH); ec != Z_STREAM_END)
return "inflate error: " + std::to_string(ec) + " " + std::string(stream.msg);
return getError("inflate error", ec, stream.msg);
return std::nullopt;
}
@ -94,7 +99,7 @@ namespace ESM4
z_stream stream{};
if (const int ec = inflateInit(&stream); ec != Z_OK)
return "inflateInit error: " + std::to_string(ec) + " " + std::string(stream.msg);
return getError("inflateInit error", ec, stream.msg);
const std::unique_ptr<z_stream, InflateEnd> streamPtr(&stream);
@ -110,8 +115,8 @@ namespace ESM4
if (ec == Z_STREAM_END)
break;
if (ec != Z_OK)
return "inflate error after reading " + std::to_string(stream.total_in)
+ " bytes: " + std::to_string(ec) + " " + std::string(stream.msg);
return getError(
"inflate error after reading " + std::to_string(stream.total_in) + " bytes", ec, stream.msg);
compressed = compressed.subspan(stream.total_in - prevTotalIn);
decompressed = decompressed.subspan(stream.total_out - prevTotalOut);
}

View file

@ -1,6 +1,7 @@
#include "shadermanager.hpp"
#include <algorithm>
#include <cassert>
#include <chrono>
#include <components/debug/debuglog.hpp>
#include <components/files/conversion.hpp>
@ -472,9 +473,15 @@ namespace Shader
{
ShaderManager::ShaderMap::iterator shaderIt
= Manager.mShaders.find(std::make_pair(templateName, shaderDefines));
if (shaderIt == Manager.mShaders.end())
{
Log(Debug::Error) << "Failed to find shader " << templateName;
continue;
}
ShaderManager::TemplateMap::iterator templateIt = Manager.mShaderTemplates.find(
templateName); // Can't be Null, if we're here it means the template was added
assert(templateIt != Manager.mShaderTemplates.end());
std::string& shaderSource = templateIt->second;
std::set<std::filesystem::path> insertedPaths;
std::filesystem::path path = (std::filesystem::path(Manager.mPath) / templateName);