From 64ba81ecf2dc6c1b8fd6e20a5fe0dc62467c7057 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 28 Oct 2020 18:02:31 +0400 Subject: [PATCH] Fix some issues, found by CoverityScan --- apps/openmw/mwmechanics/actors.cpp | 6 ++++-- apps/openmw/mwphysics/mtphysics.cpp | 1 + apps/openmw/mwrender/camera.cpp | 6 ++++++ apps/openmw/mwrender/camera.hpp | 4 ++-- apps/openmw/mwsound/soundmanagerimp.cpp | 3 +++ apps/openmw/mwsound/soundmanagerimp.hpp | 4 ++-- components/esm/loadland.cpp | 5 +++-- components/esm/loadland.hpp | 2 +- 8 files changed, 22 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 4d7841010..c027e1c89 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -590,7 +590,9 @@ namespace MWMechanics if (!actorState.isTurningToPlayer()) { - float angle = std::atan2(dir.x(), dir.y()); + float from = dir.x(); + float to = dir.y(); + float angle = std::atan2(from, to); actorState.setAngleToPlayer(angle); float deltaAngle = Misc::normalizeAngle(angle - actor.getRefData().getPosition().rot[2]); if (!mSmoothMovement || std::abs(deltaAngle) > osg::DegreesToRadians(60.f)) @@ -1723,7 +1725,7 @@ namespace MWMechanics shouldAvoidCollision = true; else if (package->getTypeId() == AiPackageTypeId::Wander && giveWayWhenIdle) { - if (!dynamic_cast(package.get())->isStationary()) + if (!static_cast(package.get())->isStationary()) shouldAvoidCollision = true; } else if (package->getTypeId() == AiPackageTypeId::Combat || package->getTypeId() == AiPackageTypeId::Pursue) diff --git a/apps/openmw/mwphysics/mtphysics.cpp b/apps/openmw/mwphysics/mtphysics.cpp index fa5a193e2..f105efce5 100644 --- a/apps/openmw/mwphysics/mtphysics.cpp +++ b/apps/openmw/mwphysics/mtphysics.cpp @@ -142,6 +142,7 @@ namespace MWPhysics { PhysicsTaskScheduler::PhysicsTaskScheduler(float physicsDt, std::shared_ptr collisionWorld) : mPhysicsDt(physicsDt) + , mTimeAccum(0.f) , mCollisionWorld(std::move(collisionWorld)) , mNumJobs(0) , mRemainingSteps(0) diff --git a/apps/openmw/mwrender/camera.cpp b/apps/openmw/mwrender/camera.cpp index 5b95b302b..b964eacff 100644 --- a/apps/openmw/mwrender/camera.cpp +++ b/apps/openmw/mwrender/camera.cpp @@ -66,6 +66,9 @@ namespace MWRender mIsNearest(false), mHeight(124.f), mBaseCameraDistance(Settings::Manager::getFloat("third person camera distance", "Camera")), + mPitch(0.f), + mYaw(0.f), + mRoll(0.f), mVanityToggleQueued(false), mVanityToggleQueuedValue(false), mViewModeToggleQueued(false), @@ -81,6 +84,9 @@ namespace MWRender mDynamicCameraDistanceEnabled(false), mShowCrosshairInThirdPersonMode(false), mHeadBobbingEnabled(Settings::Manager::getBool("head bobbing", "Camera")), + mHeadBobbingOffset(0.f), + mHeadBobbingWeight(0.f), + mTotalMovement(0.f), mDeferredRotation(osg::Vec3f()), mDeferredRotationDisabled(false) { diff --git a/apps/openmw/mwrender/camera.hpp b/apps/openmw/mwrender/camera.hpp index 6fe392683..9e2b608df 100644 --- a/apps/openmw/mwrender/camera.hpp +++ b/apps/openmw/mwrender/camera.hpp @@ -74,8 +74,8 @@ namespace MWRender bool mHeadBobbingEnabled; float mHeadBobbingOffset; - float mHeadBobbingWeight = 0; // Value from 0 to 1 for smooth enabling/disabling. - float mTotalMovement = 0; // Needed for head bobbing. + float mHeadBobbingWeight; // Value from 0 to 1 for smooth enabling/disabling. + float mTotalMovement; // Needed for head bobbing. void updateHeadBobbing(float duration); void updateFocalPointOffset(float duration); diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index d33b3d26e..1a90dceed 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -65,6 +65,9 @@ namespace MWSound , mUnderwaterSound(nullptr) , mNearWaterSound(nullptr) , mPlaybackPaused(false) + , mTimePassed(0.f) + , mLastCell(nullptr) + , mCurrentRegionSound(nullptr) { mBufferCacheMin = std::max(Settings::Manager::getInt("buffer cache min", "Sound"), 1); mBufferCacheMax = std::max(Settings::Manager::getInt("buffer cache max", "Sound"), 1); diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index 0c82528b5..f69171a09 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -116,9 +116,9 @@ namespace MWSound RegionSoundSelector mRegionSoundSelector; - float mTimePassed = 0; + float mTimePassed; - const ESM::Cell *mLastCell = nullptr; + const ESM::Cell *mLastCell; Sound* mCurrentRegionSound; diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 3064d0c31..2aa8f21db 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -331,9 +331,10 @@ namespace ESM std::copy(land.mWnam, land.mWnam + LAND_GLOBAL_MAP_LOD_SIZE, mWnam); } - Land& Land::operator= (Land land) + Land& Land::operator= (const Land& land) { - swap (land); + Land tmp(land); + swap(tmp); return *this; } diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index e5faf4b31..2a1140ad2 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -148,7 +148,7 @@ struct Land Land (const Land& land); - Land& operator= (Land land); + Land& operator= (const Land& land); void swap (Land& land);