From b6800a9992db079edcdfd5891fdd843de3a2328c Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 19 Dec 2017 18:16:41 +0200 Subject: [PATCH 1/7] X3DImporter: Add virtual destructors to some classes which already have virtual functions --- code/FIReader.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/FIReader.hpp b/code/FIReader.hpp index 5f4e5bb48..e142a571b 100644 --- a/code/FIReader.hpp +++ b/code/FIReader.hpp @@ -62,6 +62,7 @@ namespace Assimp { struct FIValue { virtual const std::string &toString() const = 0; + virtual ~FIValue() {} }; struct FIStringValue: public FIValue { @@ -121,6 +122,7 @@ struct FICDATAValue: public FIStringValue { struct FIDecoder { virtual std::shared_ptr decode(const uint8_t *data, size_t len) = 0; + virtual ~FIDecoder() {} }; struct FIQName { From 1e9f329e6daca02c0c8163bea6b3130c90b7bfc5 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 19 Dec 2017 18:18:14 +0200 Subject: [PATCH 2/7] MMD: Add virtual destructor to a class which already has virtual functions --- code/MMDPmxParser.h | 1 + 1 file changed, 1 insertion(+) diff --git a/code/MMDPmxParser.h b/code/MMDPmxParser.h index 989cffed6..a26eddb04 100644 --- a/code/MMDPmxParser.h +++ b/code/MMDPmxParser.h @@ -87,6 +87,7 @@ namespace pmx { public: virtual void Read(std::istream *stream, PmxSetting *setting) = 0; + virtual ~PmxVertexSkinning() {} }; class PmxVertexSkinningBDEF1 : public PmxVertexSkinning From 65ffeaa81e10efcd49b1fe0d29ffe8ca51bbf8da Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 19 Dec 2017 18:24:03 +0200 Subject: [PATCH 3/7] ObjImporter: Use unique_ptr --- code/ObjFileImporter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 9f3bdef97..5fa57e108 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -317,7 +317,7 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj return NULL; } - aiMesh* pMesh = new aiMesh; + std::unique_ptr pMesh(new aiMesh); if( !pObjMesh->m_name.empty() ) { pMesh->mName.Set( pObjMesh->m_name ); } @@ -382,9 +382,9 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj } // Create mesh vertices - createVertexArray(pModel, pData, meshIndex, pMesh, uiIdxCount); + createVertexArray(pModel, pData, meshIndex, pMesh.get(), uiIdxCount); - return pMesh; + return pMesh.release(); } // ------------------------------------------------------------------------------------------------ From 0cf772a4d44de87f0db1c026ec40892c181475a1 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 19 Dec 2017 18:46:48 +0200 Subject: [PATCH 4/7] MDCLoader: Replace min and strlen with strnlen --- code/MDCLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/MDCLoader.cpp b/code/MDCLoader.cpp index 21aca53ff..8b3140108 100644 --- a/code/MDCLoader.cpp +++ b/code/MDCLoader.cpp @@ -294,8 +294,8 @@ void MDCImporter::InternReadFile( pcMesh->mMaterialIndex = (unsigned int)aszShaders.size(); // create a new shader - aszShaders.push_back(std::string( pcShader->ucName, std::min( - ::strlen(pcShader->ucName),sizeof(pcShader->ucName)) )); + aszShaders.push_back(std::string( pcShader->ucName, + ::strnlen(pcShader->ucName, sizeof(pcShader->ucName)) )); } // need to create a default material else if (UINT_MAX == iDefaultMatIndex) From 47b725a8c8c9f783a959256bfa25eea10b516dd4 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 19 Dec 2017 18:55:14 +0200 Subject: [PATCH 5/7] MDCLoader: Fix horrible pointer casting hack --- code/MDCLoader.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/code/MDCLoader.cpp b/code/MDCLoader.cpp index 8b3140108..8af18992d 100644 --- a/code/MDCLoader.cpp +++ b/code/MDCLoader.cpp @@ -283,9 +283,8 @@ void MDCImporter::InternReadFile( pcMesh->mNumVertices = pcMesh->mNumFaces * 3; // store the name of the surface for use as node name. - // FIX: make sure there is a 0 termination - const_cast(pcSurface->ucName[AI_MDC_MAXQPATH-1]) = '\0'; - pcMesh->mTextureCoords[3] = (aiVector3D*)pcSurface->ucName; + pcMesh->mName.Set(std::string(pcSurface->ucName + , strnlen(pcSurface->ucName, AI_MDC_MAXQPATH - 1))); // go to the first shader in the file. ignore the others. if (pcSurface->ulNumShaders) @@ -432,7 +431,7 @@ void MDCImporter::InternReadFile( else if (1 == pScene->mNumMeshes) { pScene->mRootNode = new aiNode(); - pScene->mRootNode->mName.Set(std::string((const char*)pScene->mMeshes[0]->mTextureCoords[3])); + pScene->mRootNode->mName = pScene->mMeshes[0]->mName; pScene->mRootNode->mNumMeshes = 1; pScene->mRootNode->mMeshes = new unsigned int[1]; pScene->mRootNode->mMeshes[0] = 0; @@ -447,17 +446,13 @@ void MDCImporter::InternReadFile( { aiNode* pcNode = pScene->mRootNode->mChildren[i] = new aiNode(); pcNode->mParent = pScene->mRootNode; - pcNode->mName.Set(std::string((const char*)pScene->mMeshes[i]->mTextureCoords[3])); + pcNode->mName = pScene->mMeshes[i]->mName; pcNode->mNumMeshes = 1; pcNode->mMeshes = new unsigned int[1]; pcNode->mMeshes[0] = i; } } - // make sure we invalidate the pointer to the mesh name - for (unsigned int i = 0; i < pScene->mNumMeshes;++i) - pScene->mMeshes[i]->mTextureCoords[3] = NULL; - // create materials pScene->mNumMaterials = (unsigned int)aszShaders.size(); pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials]; From c44522d4db95f685db0cedd2f0b85102f152b623 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 19 Dec 2017 19:38:38 +0200 Subject: [PATCH 6/7] ObjImporter: Fix possible memory leak --- code/ObjFileImporter.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 5fa57e108..e1a084d62 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -264,8 +264,12 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile { unsigned int meshId = pObject->m_Meshes[ i ]; aiMesh *pMesh = createTopology( pModel, pObject, meshId ); - if( pMesh && pMesh->mNumFaces > 0 ) { - MeshArray.push_back( pMesh ); + if( pMesh ) { + if (pMesh->mNumFaces > 0) { + MeshArray.push_back( pMesh ); + } else { + delete pMesh; + } } } From bb5495f99a7835bc2bdcfe2dc68fb086f67defec Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 19 Dec 2017 19:39:04 +0200 Subject: [PATCH 7/7] Q3BSP: Add assertion to silence a static analyzer warning --- code/Q3BSPFileImporter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/Q3BSPFileImporter.cpp b/code/Q3BSPFileImporter.cpp index 9d6d8e870..0cdafae42 100644 --- a/code/Q3BSPFileImporter.cpp +++ b/code/Q3BSPFileImporter.cpp @@ -447,6 +447,7 @@ void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel, pMesh->mTextureCoords[ 0 ][ rVertIdx ].Set( pVertex->vTexCoord.x, pVertex->vTexCoord.y, 0.0f ); pMesh->mTextureCoords[ 1 ][ rVertIdx ].Set( pVertex->vLightmap.x, pVertex->vLightmap.y, 0.0f ); + ai_assert( m_pCurrentFace ); m_pCurrentFace->mIndices[ idx ] = rVertIdx; rVertIdx++;