From a3dd4153aaae9fb7d0776417502b2112efdbac8f Mon Sep 17 00:00:00 2001 From: Sergei Marochkin Date: Tue, 25 Dec 2018 19:55:21 +0300 Subject: [PATCH] Fix issues reported by PVS-Studio --- CMakeLists.txt | 8 ++++++-- src/CFunctions.cpp | 2 +- src/CFunctions.hpp | 2 +- src/vendor/ColAndreas/ColAndreasDatabaseReader.cpp | 2 +- src/vendor/ColAndreas/ColAndreasDatabaseReader.h | 2 +- src/vendor/ColAndreas/ColObject.cpp | 11 +++++------ src/vendor/ColAndreas/ColObject.h | 6 ++---- src/vendor/ColAndreas/DynamicWorld.cpp | 2 +- src/vendor/ColAndreas/DynamicWorld.h | 2 +- 9 files changed, 19 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f17a0c3..a3b6bee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,8 +37,12 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # flags set (USE_MSVC_RUNTIME_LIBRARY_DLL true) - set (CMAKE_C_FLAGS "/Zp1 /W4 /MT") - set (CMAKE_CXX_FLAGS "/Zp1 /W4 /EHsc /MT") + set (CMAKE_C_FLAGS "/Zp1 /W4") + set (CMAKE_CXX_FLAGS "/Zp1 /W4 /EHsc") + set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT") + set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd") + set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") + set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") set (CMAKE_SHARED_LINKER_FLAGS "/NOLOGO /MACHINE:X86") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") add_definitions (-DLINUX -DSYSTEM_NAME="GNU/Linux") diff --git a/src/CFunctions.cpp b/src/CFunctions.cpp index c866677..b764978 100644 --- a/src/CFunctions.cpp +++ b/src/CFunctions.cpp @@ -814,7 +814,7 @@ WORD CFunctions::GetClosestMapPointInBetween(const CVector &vecHitOrigin, const } -WORD CFunctions::RayCastLine(const CVector vecStart, const CVector vecEnd, CVector *vecResult) +WORD CFunctions::RayCastLine(const CVector &vecStart, const CVector &vecEnd, CVector *vecResult) { btVector3 Start = btVector3(btScalar(vecStart.fX + 0.00001), btScalar(vecStart.fY + 0.00001), btScalar(vecStart.fZ + 0.00001)); btVector3 End = btVector3(btScalar(vecEnd.fX), btScalar(vecEnd.fY), btScalar(vecEnd.fZ)); diff --git a/src/CFunctions.hpp b/src/CFunctions.hpp index 55067e6..ceb0301 100644 --- a/src/CFunctions.hpp +++ b/src/CFunctions.hpp @@ -67,7 +67,7 @@ class CFunctions static void PlayerShoot(WORD wPlayerId, WORD wHitId, BYTE byteHitType, BYTE byteWeaponId, const CVector &vecPoint, const CVector &vecOffsetFrom, bool bIsHit, BYTE byteBetweenCheckFlags); static WORD GetClosestEntityInBetween(const CVector &vecHitOrigin, const CVector &vecHitTarget, float fRange, BYTE byteBetweenCheckFlags, WORD wPlayerId, WORD wTargetId, BYTE &byteEntityType, WORD &wPlayerObjectOwnerId, CVector &vecHitMap); - static WORD RayCastLine(const CVector vecStart, const CVector vecEnd, CVector *vecResult); + static WORD RayCastLine(const CVector &vecStart, const CVector &vecEnd, CVector *vecResult); // Functions static ClientJoin_RPC_t pfn__ClientJoin_RPC; diff --git a/src/vendor/ColAndreas/ColAndreasDatabaseReader.cpp b/src/vendor/ColAndreas/ColAndreasDatabaseReader.cpp index 16f40b1..1f6949b 100644 --- a/src/vendor/ColAndreas/ColAndreasDatabaseReader.cpp +++ b/src/vendor/ColAndreas/ColAndreasDatabaseReader.cpp @@ -14,7 +14,7 @@ void DeleteCollisionData() delete ModelPlacements; } -bool ReadColandreasDatabaseFile(const std::string FileLocation) +bool ReadColandreasDatabaseFile(const std::string &FileLocation) { bool returnValue = false; diff --git a/src/vendor/ColAndreas/ColAndreasDatabaseReader.h b/src/vendor/ColAndreas/ColAndreasDatabaseReader.h index 43872a7..44a2cd6 100644 --- a/src/vendor/ColAndreas/ColAndreasDatabaseReader.h +++ b/src/vendor/ColAndreas/ColAndreasDatabaseReader.h @@ -105,7 +105,7 @@ pass a refrence to the collisionmodel and itemplacment array's. The function wil returns a boolean true if function suceeded, otherwise false. */ -bool ReadColandreasDatabaseFile(const std::string FileLocation); +bool ReadColandreasDatabaseFile(const std::string &FileLocation); extern CollisionModelstructure* CollisionModels; extern ItemPlacementstructure* ModelPlacements; extern uint16_t ModelCount; diff --git a/src/vendor/ColAndreas/ColObject.cpp b/src/vendor/ColAndreas/ColObject.cpp index 403e504..6c4da18 100644 --- a/src/vendor/ColAndreas/ColObject.cpp +++ b/src/vendor/ColAndreas/ColObject.cpp @@ -77,6 +77,7 @@ bool LoadCollisionData(btDynamicsWorld* collisionWorld) ColAndreasColObject* convex = new ColAndreasColObject(i, true); //true for convex mesh colObjects.push_back(colObject); colConvex.push_back(convex->getCompoundShape()); //storing convex bodies + delete convex; } return true; } @@ -86,7 +87,7 @@ bool LoadCollisionData(btDynamicsWorld* collisionWorld) ColAndreasMapObject::ColAndreasMapObject(uint16_t modelid, const btQuaternion& objectRot, const btVector3& objectPos, btDynamicsWorld* world) { - colindex = ModelRef[modelid]; + uint16_t colindex = ModelRef[modelid]; collisionWorld = world; @@ -298,7 +299,7 @@ RemovedBuildingManager::RemovedBuildingManager() { } -bool RemovedBuildingManager::isRemoved(uint16_t model, const Vector position) +bool RemovedBuildingManager::isRemoved(uint16_t model, const Vector &position) { for (uint16_t i = 0; i < removedBuildings.size(); i++) { if (model == removedBuildings[i].r_Model) { @@ -313,7 +314,7 @@ bool RemovedBuildingManager::isRemoved(uint16_t model, const Vector position) return 0; } -void RemovedBuildingManager::addBuilding(const removeBuildingData removeData) +void RemovedBuildingManager::addBuilding(const removeBuildingData &removeData) { removedBuildings.push_back(removeData); } @@ -336,9 +337,7 @@ void InitCollisionMap(btDynamicsWorld* collisionWorld, RemovedBuildingManager* r // Continue if model has no collision if (index == 65535) continue; - ColAndreasMapObject* tmpObject; - tmpObject = new ColAndreasMapObject(ModelPlacements[i].Modelid, btQuaternion(ModelPlacements[i].Rotation.x, ModelPlacements[i].Rotation.y, ModelPlacements[i].Rotation.z, ModelPlacements[i].Rotation.w), btVector3(ModelPlacements[i].Position.x, ModelPlacements[i].Position.y, ModelPlacements[i].Position.z), collisionWorld); - + ColAndreasMapObject(ModelPlacements[i].Modelid, btQuaternion(ModelPlacements[i].Rotation.x, ModelPlacements[i].Rotation.y, ModelPlacements[i].Rotation.z, ModelPlacements[i].Rotation.w), btVector3(ModelPlacements[i].Position.x, ModelPlacements[i].Position.y, ModelPlacements[i].Position.z), collisionWorld); } } } diff --git a/src/vendor/ColAndreas/ColObject.h b/src/vendor/ColAndreas/ColObject.h index 4fde345..f4613ff 100644 --- a/src/vendor/ColAndreas/ColObject.h +++ b/src/vendor/ColAndreas/ColObject.h @@ -17,8 +17,6 @@ struct removeBuildingData float r_Radius; }; -static uint16_t colindex = 0; - // Data structure to track in-game objects with respect to their colindex struct ColAndreasObjectTracker { @@ -112,8 +110,8 @@ class RemovedBuildingManager { public: RemovedBuildingManager(); - bool isRemoved(uint16_t model, const Vector position); - void addBuilding(const removeBuildingData removeData); + bool isRemoved(uint16_t model, const Vector &position); + void addBuilding(const removeBuildingData &removeData); private: std::vector removedBuildings; }; diff --git a/src/vendor/ColAndreas/DynamicWorld.cpp b/src/vendor/ColAndreas/DynamicWorld.cpp index 35d7c49..11932c3 100644 --- a/src/vendor/ColAndreas/DynamicWorld.cpp +++ b/src/vendor/ColAndreas/DynamicWorld.cpp @@ -260,7 +260,7 @@ void ColAndreasWorld::colandreasInitMap() InitCollisionMap(this->dynamicsWorld, this->removedManager); } -uint16_t ColAndreasWorld::createColAndreasMapObject(uint16_t addtomanager, uint16_t modelid, const btQuaternion& objectRot, const btVector3& objectPos) +int ColAndreasWorld::createColAndreasMapObject(uint16_t addtomanager, uint16_t modelid, const btQuaternion& objectRot, const btVector3& objectPos) { if (addtomanager) { return this->objectManager->addObjectManager(new ColAndreasMapObject(modelid, objectRot, objectPos, this->dynamicsWorld)); diff --git a/src/vendor/ColAndreas/DynamicWorld.h b/src/vendor/ColAndreas/DynamicWorld.h index f9fe7e0..e9fea52 100644 --- a/src/vendor/ColAndreas/DynamicWorld.h +++ b/src/vendor/ColAndreas/DynamicWorld.h @@ -55,7 +55,7 @@ class ColAndreasWorld int performRayTestNormal(const btVector3& Start, const btVector3& End, btVector3& Result, btVector3& Normal, uint16_t& model); int performContactTest(uint16_t modelid, btVector3& objectPos, btQuaternion& objectRot); - uint16_t createColAndreasMapObject(uint16_t addtomanager, uint16_t modelid, const btQuaternion& objectRot, const btVector3& objectPos); + int createColAndreasMapObject(uint16_t addtomanager, uint16_t modelid, const btQuaternion& objectRot, const btVector3& objectPos); uint16_t getModelRef(uint16_t model); void colandreasInitMap(); bool loadCollisionData();