Merge pull request #2172 from akortunov/pvs_fix

Fix some issues, found by PVS-Studio
This commit is contained in:
Bret Curtis 2019-02-22 15:01:37 +01:00 committed by GitHub
commit 212f097b3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 40 additions and 37 deletions

View File

@ -84,6 +84,8 @@ namespace ESSImport
mGlobalMapState.mBounds.mMaxX = 0; mGlobalMapState.mBounds.mMaxX = 0;
mGlobalMapState.mBounds.mMinY = 0; mGlobalMapState.mBounds.mMinY = 0;
mGlobalMapState.mBounds.mMaxY = 0; mGlobalMapState.mBounds.mMaxY = 0;
mPlayerBase.blank();
} }
int generateActorId() int generateActorId()

View File

@ -258,6 +258,9 @@ OMW::Engine::~Engine()
mViewer = nullptr; mViewer = nullptr;
delete mEncoder;
mEncoder = nullptr;
if (mWindow) if (mWindow)
{ {
SDL_DestroyWindow(mWindow); SDL_DestroyWindow(mWindow);
@ -657,8 +660,7 @@ void OMW::Engine::go()
settingspath = loadSettings (settings); settingspath = loadSettings (settings);
// Create encoder // Create encoder
ToUTF8::Utf8Encoder encoder (mEncoding); mEncoder = new ToUTF8::Utf8Encoder(mEncoding);
mEncoder = &encoder;
// Setup viewer // Setup viewer
mViewer = new osgViewer::Viewer; mViewer = new osgViewer::Viewer;

View File

@ -780,7 +780,7 @@ namespace MWClass
MWWorld::Ptr armor = ((armorslot != inv.end()) ? *armorslot : MWWorld::Ptr()); MWWorld::Ptr armor = ((armorslot != inv.end()) ? *armorslot : MWWorld::Ptr());
if(!armor.isEmpty() && armor.getTypeName() == typeid(ESM::Armor).name()) if(!armor.isEmpty() && armor.getTypeName() == typeid(ESM::Armor).name())
{ {
if (attacker.isEmpty() || (!attacker.isEmpty() && !(object.isEmpty() && !attacker.getClass().isNpc()))) // Unarmed creature attacks don't affect armor condition if (!object.isEmpty() || attacker.isEmpty() || attacker.getClass().isNpc()) // Unarmed creature attacks don't affect armor condition
{ {
int armorhealth = armor.getClass().getItemHealth(armor); int armorhealth = armor.getClass().getItemHealth(armor);
armorhealth -= std::min(damageDiff, armorhealth); armorhealth -= std::min(damageDiff, armorhealth);

View File

@ -262,7 +262,7 @@ namespace MWGui
if (mode == GM_Console) if (mode == GM_Console)
MWBase::Environment::get().getWindowManager()->setConsoleSelectedObject(object); MWBase::Environment::get().getWindowManager()->setConsoleSelectedObject(object);
else if ((mode == GM_Container) || (mode == GM_Inventory)) else //if ((mode == GM_Container) || (mode == GM_Inventory))
{ {
// pick up object // pick up object
if (!object.isEmpty()) if (!object.isEmpty())

View File

@ -631,7 +631,7 @@ namespace
if (page+2 < book->pageCount()) if (page+2 < book->pageCount())
{ {
MWBase::Environment::get().getWindowManager()->playSound("book page", true); MWBase::Environment::get().getWindowManager()->playSound("book page");
page += 2; page += 2;
updateShowingPages (); updateShowingPages ();
@ -649,7 +649,7 @@ namespace
if(page >= 2) if(page >= 2)
{ {
MWBase::Environment::get().getWindowManager()->playSound("book page", true); MWBase::Environment::get().getWindowManager()->playSound("book page");
page -= 2; page -= 2;
updateShowingPages (); updateShowingPages ();

View File

@ -327,11 +327,9 @@ namespace MWGui
addGroup(MWBase::Environment::get().getWindowManager()->getGameSettingString(titleId, titleDefault), coord1, coord2); addGroup(MWBase::Environment::get().getWindowManager()->getGameSettingString(titleId, titleDefault), coord1, coord2);
SkillList::const_iterator end = skills.end(); for (const int& skillId : skills)
for (SkillList::const_iterator it = skills.begin(); it != end; ++it)
{ {
int skillId = *it; if (skillId < 0 || skillId >= ESM::Skill::Length) // Skip unknown skill indexes
if (skillId < 0 || skillId > ESM::Skill::Length) // Skip unknown skill indexes
continue; continue;
assert(skillId >= 0 && skillId < ESM::Skill::Length); assert(skillId >= 0 && skillId < ESM::Skill::Length);
const std::string &skillNameId = ESM::Skill::sSkillNameIds[skillId]; const std::string &skillNameId = ESM::Skill::sSkillNameIds[skillId];

View File

@ -41,7 +41,7 @@ namespace MWGui
else if (skill < ESM::Skill::Length) else if (skill < ESM::Skill::Length)
setSkillId(static_cast<ESM::Skill::SkillEnum>(skill)); setSkillId(static_cast<ESM::Skill::SkillEnum>(skill));
else else
throw new std::runtime_error("Skill number out of range"); throw std::runtime_error("Skill number out of range");
} }
void MWSkill::setSkillValue(const SkillValue& value) void MWSkill::setSkillValue(const SkillValue& value)

View File

@ -12,7 +12,7 @@
#include "steering.hpp" #include "steering.hpp"
MWMechanics::AiAvoidDoor::AiAvoidDoor(const MWWorld::ConstPtr& doorPtr) MWMechanics::AiAvoidDoor::AiAvoidDoor(const MWWorld::ConstPtr& doorPtr)
: AiPackage(), mDuration(1), mDoorPtr(doorPtr), mAdjAngle(0) : AiPackage(), mDuration(1), mDoorPtr(doorPtr), mLastPos(ESM::Position()), mAdjAngle(0)
{ {
} }

View File

@ -328,32 +328,32 @@ void ActorAnimation::updateQuiver()
suitableAmmo = ammo->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::Arrow; suitableAmmo = ammo->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::Arrow;
} }
if (ammoNode && suitableAmmo) if (!suitableAmmo)
return;
// We should not show more ammo than equipped and more than quiver mesh has
ammoCount = std::min(ammoCount, ammoNode->getNumChildren());
// Remove existing ammo nodes
for (unsigned int i=0; i<ammoNode->getNumChildren(); ++i)
{ {
// We should not show more ammo than equipped and more than quiver mesh has osg::ref_ptr<osg::Group> arrowNode = ammoNode->getChild(i)->asGroup();
ammoCount = std::min(ammoCount, ammoNode->getNumChildren()); if (!arrowNode->getNumChildren())
continue;
// Remove existing ammo nodes osg::ref_ptr<osg::Node> arrowChildNode = arrowNode->getChild(0);
for (unsigned int i=0; i<ammoNode->getNumChildren(); ++i) arrowNode->removeChild(arrowChildNode);
{ }
osg::ref_ptr<osg::Group> arrowNode = ammoNode->getChild(i)->asGroup();
if (!arrowNode->getNumChildren())
continue;
osg::ref_ptr<osg::Node> arrowChildNode = arrowNode->getChild(0); // Add new ones
arrowNode->removeChild(arrowChildNode); osg::Vec4f glowColor = getEnchantmentColor(*ammo);
} std::string model = ammo->getClass().getModel(*ammo);
for (unsigned int i=0; i<ammoCount; ++i)
// Add new ones {
osg::Vec4f glowColor = getEnchantmentColor(*ammo); osg::ref_ptr<osg::Group> arrowNode = ammoNode->getChild(i)->asGroup();
std::string model = ammo->getClass().getModel(*ammo); osg::ref_ptr<osg::Node> arrow = mResourceSystem->getSceneManager()->getInstance(model, arrowNode);
for (unsigned int i=0; i<ammoCount; ++i) if (!ammo->getClass().getEnchantment(*ammo).empty())
{ addGlow(arrow, glowColor);
osg::ref_ptr<osg::Group> arrowNode = ammoNode->getChild(i)->asGroup();
osg::ref_ptr<osg::Node> arrow = mResourceSystem->getSceneManager()->getInstance(model, arrowNode);
if (!ammo->getClass().getEnchantment(*ammo).empty())
addGlow(arrow, glowColor);
}
} }
} }

View File

@ -30,6 +30,7 @@ namespace MWWorld
Player::Player (const ESM::NPC *player) Player::Player (const ESM::NPC *player)
: mCellStore(0), : mCellStore(0),
mLastKnownExteriorPosition(0,0,0), mLastKnownExteriorPosition(0,0,0),
mMarkedPosition(ESM::Position()),
mMarkedCell(nullptr), mMarkedCell(nullptr),
mAutoMove(false), mAutoMove(false),
mForwardBackward(0), mForwardBackward(0),

View File

@ -876,7 +876,7 @@ QStringList Wizard::UnshieldWorker::findFiles(const QString &fileName, const QSt
result.append(info.absoluteFilePath()); result.append(info.absoluteFilePath());
break; break;
case Qt::MatchEndsWith: case Qt::MatchEndsWith:
if (info.fileName().endsWith(fileName), Qt::CaseInsensitive) if (info.fileName().endsWith(fileName, Qt::CaseInsensitive))
result.append(info.absoluteFilePath()); result.append(info.absoluteFilePath());
break; break;
} }

View File

@ -368,7 +368,7 @@ InputWrapper::InputWrapper(SDL_Window* window, osg::ref_ptr<osgViewer::Viewer> v
} }
else else
{ {
throw new std::runtime_error("Tried to package non-motion event!"); throw std::runtime_error("Tried to package non-motion event!");
} }
return pack_evt; return pack_evt;