From 696cf9ab05af25af0a305b34ed9feb8af788d545 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 14 Apr 2021 08:06:22 +0400 Subject: [PATCH 1/8] Extend variables range to avoid integer overflow --- components/nif/data.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index 415a013b3..b6674611b 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -363,11 +363,11 @@ void NiSkinPartition::read(NIFStream *nif) void NiSkinPartition::Partition::read(NIFStream *nif) { - unsigned short numVertices = nif->getUShort(); - unsigned short numTriangles = nif->getUShort(); - unsigned short numBones = nif->getUShort(); - unsigned short numStrips = nif->getUShort(); - unsigned short bonesPerVertex = nif->getUShort(); + size_t numVertices = nif->getUShort(); + size_t numTriangles = nif->getUShort(); + size_t numBones = nif->getUShort(); + size_t numStrips = nif->getUShort(); + size_t bonesPerVertex = nif->getUShort(); if (numBones) nif->getUShorts(bones, numBones); @@ -395,7 +395,7 @@ void NiSkinPartition::Partition::read(NIFStream *nif) if (numStrips) { strips.resize(numStrips); - for (unsigned short i = 0; i < numStrips; i++) + for (size_t i = 0; i < numStrips; i++) nif->getUShorts(strips[i], stripLengths[i]); } else if (numTriangles) From 388573cf6030e5867f7567493b05541b2eb02598 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 14 Apr 2021 08:07:08 +0400 Subject: [PATCH 2/8] Fix uninitialized fields in the essimporter --- apps/essimporter/convertscpt.cpp | 1 + apps/essimporter/importinventory.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/apps/essimporter/convertscpt.cpp b/apps/essimporter/convertscpt.cpp index ca81ebbbf..cb7947e40 100644 --- a/apps/essimporter/convertscpt.cpp +++ b/apps/essimporter/convertscpt.cpp @@ -11,6 +11,7 @@ namespace ESSImport { out.mId = Misc::StringUtils::lowerCase(scpt.mSCHD.mName.toString()); out.mRunning = scpt.mRunning; + out.mTargetRef.unset(); // TODO: convert target reference of global script convertSCRI(scpt.mSCRI, out.mLocals); } diff --git a/apps/essimporter/importinventory.cpp b/apps/essimporter/importinventory.cpp index dbf9ce0bd..e91c39452 100644 --- a/apps/essimporter/importinventory.cpp +++ b/apps/essimporter/importinventory.cpp @@ -19,6 +19,7 @@ namespace ESSImport item.mCount = contItem.mCount; item.mRelativeEquipmentSlot = -1; item.mLockLevel = 0; + item.mRefNum.unset(); unsigned int itemCount = std::abs(item.mCount); bool separateStacks = false; From 5f6f2c15b16f1b01e9d0969f4b10d23b867b266a Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 14 Apr 2021 08:07:43 +0400 Subject: [PATCH 3/8] An another attempt to suppress Coverity warning about mkstemp --- components/crashcatcher/crashcatcher.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/crashcatcher/crashcatcher.cpp b/components/crashcatcher/crashcatcher.cpp index b4b2a4a0c..e0a5c964f 100644 --- a/components/crashcatcher/crashcatcher.cpp +++ b/components/crashcatcher/crashcatcher.cpp @@ -150,6 +150,9 @@ static void gdb_info(pid_t pid) * So CoverityScan warning is valid only for ancient versions of stdlib. */ strcpy(respfile, "/tmp/gdb-respfile-XXXXXX"); +#ifdef __COVERITY__ + umask(0600); +#endif if((fd=mkstemp(respfile)) >= 0 && (f=fdopen(fd, "w")) != nullptr) { fprintf(f, "attach %d\n" From e309f75938119d1ea96c6e180f9aad36fb8602e3 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 14 Apr 2021 08:07:56 +0400 Subject: [PATCH 4/8] Join variables declaration and usage --- components/shader/shadervisitor.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/shader/shadervisitor.cpp b/components/shader/shadervisitor.cpp index b0013538f..e8ac7d9c3 100644 --- a/components/shader/shadervisitor.cpp +++ b/components/shader/shadervisitor.cpp @@ -278,8 +278,7 @@ namespace Shader const osg::StateSet::AttributeList& attributes = stateset->getAttributeList(); osg::StateSet::AttributeList removedAttributes; - osg::ref_ptr removedState; - if (removedState = getRemovedState(*stateset)) + if (osg::ref_ptr removedState = getRemovedState(*stateset)) removedAttributes = removedState->getAttributeList(); for (const auto& attributeMap : { attributes, removedAttributes }) { @@ -475,8 +474,7 @@ namespace Shader writableStateSet->removeAttribute(osg::StateAttribute::PROGRAM); - osg::ref_ptr removedState; - if (removedState = getRemovedState(*writableStateSet)) + if (osg::ref_ptr removedState = getRemovedState(*writableStateSet)) { // user data is normally shallow copied so shared with the original stateset osg::ref_ptr writableUserData; From bce6effe955ae116754753dd2fdd257627c8ac56 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 14 Apr 2021 08:20:23 +0400 Subject: [PATCH 5/8] Fix uninitialized variables in the LightManager --- components/sceneutil/lightmanager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index c03bbca59..1735f6b8b 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -400,7 +400,7 @@ namespace SceneUtil class LightStateAttributePerObjectUniform : public osg::StateAttribute { public: - LightStateAttributePerObjectUniform() {} + LightStateAttributePerObjectUniform() : mLightManager(nullptr) {} LightStateAttributePerObjectUniform(const std::vector>& lights, LightManager* lightManager) : mLights(lights), mLightManager(lightManager) {} LightStateAttributePerObjectUniform(const LightStateAttributePerObjectUniform& copy,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) @@ -613,7 +613,7 @@ namespace SceneUtil class LightManagerCullCallback : public osg::NodeCallback { public: - LightManagerCullCallback(LightManager* lightManager) : mLightManager(lightManager) {} + LightManagerCullCallback(LightManager* lightManager) : mLightManager(lightManager), mLastFrameNumber(0) {} void operator()(osg::Node* node, osg::NodeVisitor* nv) override { @@ -903,6 +903,10 @@ namespace SceneUtil , mLightingMask(copy.mLightingMask) , mSun(copy.mSun) , mLightingMethod(copy.mLightingMethod) + , mPointLightRadiusMultiplier(copy.mPointLightRadiusMultiplier) + , mPointLightFadeEnd(copy.mPointLightFadeEnd) + , mPointLightFadeStart(copy.mPointLightFadeStart) + , mMaxLights(copy.mMaxLights) { } From ac347810ca7a5fadc5d4f9729006e65350cc57c5 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 14 Apr 2021 08:36:17 +0400 Subject: [PATCH 6/8] Fix uninitialized field in the mouse event --- components/sdlutil/sdlinputwrapper.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/sdlutil/sdlinputwrapper.cpp b/components/sdlutil/sdlinputwrapper.cpp index ca223ae3b..57b211e97 100644 --- a/components/sdlutil/sdlinputwrapper.cpp +++ b/components/sdlutil/sdlinputwrapper.cpp @@ -368,6 +368,7 @@ InputWrapper::InputWrapper(SDL_Window* window, osg::ref_ptr v pack_evt.yrel = 0; pack_evt.z = mMouseZ; pack_evt.zrel = 0; + pack_evt.timestamp = 0; if(evt.type == SDL_MOUSEMOTION) { From 0c7ddd393801bb5f178e83632b20a3c7e14e6fb8 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 14 Apr 2021 08:47:55 +0400 Subject: [PATCH 7/8] Remove redundant qualifiers --- components/sceneutil/lightmanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index 1735f6b8b..c9826c0e8 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -861,7 +861,7 @@ namespace SceneUtil if (ffp) { - initFFP(LightManager::mFFPMaxLights); + initFFP(mFFPMaxLights); return; } @@ -1044,7 +1044,7 @@ namespace SceneUtil auto* stateset = getOrCreateStateSet(); setLightingMethod(LightingMethod::PerObjectUniform); - setMaxLights(std::clamp(targetLights, mMaxLightsLowerLimit, LightManager::mMaxLightsUpperLimit)); + setMaxLights(std::clamp(targetLights, mMaxLightsLowerLimit, mMaxLightsUpperLimit)); stateset->setAttributeAndModes(new LightManagerStateAttributePerObjectUniform(this), osg::StateAttribute::ON); stateset->addUniform(new osg::Uniform(osg::Uniform::FLOAT_MAT4, "LightBuffer", getMaxLights())); @@ -1053,7 +1053,7 @@ namespace SceneUtil void LightManager::initSingleUBO(int targetLights) { setLightingMethod(LightingMethod::SingleUBO); - setMaxLights(std::clamp(targetLights, mMaxLightsLowerLimit, LightManager::mMaxLightsUpperLimit)); + setMaxLights(std::clamp(targetLights, mMaxLightsLowerLimit, mMaxLightsUpperLimit)); for (int i = 0; i < 2; ++i) { From 016a1d45dfde4b4d66f00ab3759669e810fc1fcf Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 14 Apr 2021 10:58:44 +0400 Subject: [PATCH 8/8] Remove outdated field - remnant from earlier implementation --- apps/opencs/model/world/data.cpp | 14 -------------- components/esm/loadtes3.cpp | 1 - components/esm/loadtes3.hpp | 1 - 3 files changed, 16 deletions(-) diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 319334c9b..4ccd2a06d 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -986,20 +986,6 @@ int CSMWorld::Data::startLoading (const boost::filesystem::path& path, bool base mMetaData.setRecord (0, Record (RecordBase::State_ModifiedOnly, nullptr, &metaData)); } - // Fix uninitialized master data index - for (std::vector::const_iterator masterData = mReader->getGameFiles().begin(); - masterData != mReader->getGameFiles().end(); ++masterData) - { - std::map::iterator nameResult = mContentFileNames.find(masterData->name); - if (nameResult != mContentFileNames.end()) - { - ESM::Header::MasterData& hackedMasterData = const_cast(*masterData); - - - hackedMasterData.index = nameResult->second; - } - } - return mReader->getRecordCount(); } diff --git a/components/esm/loadtes3.cpp b/components/esm/loadtes3.cpp index 84a31b3bd..d953f1dc2 100644 --- a/components/esm/loadtes3.cpp +++ b/components/esm/loadtes3.cpp @@ -42,7 +42,6 @@ void ESM::Header::load (ESMReader &esm) MasterData m; m.name = esm.getHString(); m.size = esm.getHNLong ("DATA"); - m.index = -1; mMaster.push_back (m); } diff --git a/components/esm/loadtes3.hpp b/components/esm/loadtes3.hpp index 5b26ac7d2..014e2a136 100644 --- a/components/esm/loadtes3.hpp +++ b/components/esm/loadtes3.hpp @@ -49,7 +49,6 @@ namespace ESM { std::string name; uint64_t size; - int index; // Position of the parent file in the global list of loaded files }; GMDT mGameData; // Used in .ess savegames only