From 4c6db68d34906d6686683ce382dd49c327ab118a Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 27 Dec 2018 22:28:23 +0100 Subject: [PATCH] Coverity-findings --- code/FBXExportNode.h | 19 ++++++++++++++++--- code/FBXExporter.cpp | 16 +++++++++------- code/XGLLoader.cpp | 10 ++++------ code/glTF2AssetWriter.inl | 3 +++ code/glTF2Exporter.cpp | 5 ++++- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/code/FBXExportNode.h b/code/FBXExportNode.h index 5ddd8c77b..b9cd5156f 100644 --- a/code/FBXExportNode.h +++ b/code/FBXExportNode.h @@ -70,14 +70,27 @@ public: // public data members bool force_has_children = false; public: // constructors + /// The default class constructor. Node() = default; - Node(const std::string& n) : name(n) {} + + /// The class constructor with the name. + Node(const std::string& n) + : name(n) + , properties() + , children() + , force_has_children( false ) { + // empty + } // convenience template to construct with properties directly template Node(const std::string& n, const More... more) - : name(n) - { AddProperties(more...); } + : name(n) + , properties() + , children() + , force_has_children(false) { + AddProperties(more...); + } public: // functions to add properties or children // add a single property to the node diff --git a/code/FBXExporter.cpp b/code/FBXExporter.cpp index 037520641..2e153dde0 100644 --- a/code/FBXExporter.cpp +++ b/code/FBXExporter.cpp @@ -131,13 +131,15 @@ namespace Assimp { } // end of namespace Assimp -FBXExporter::FBXExporter ( - const aiScene* pScene, - const ExportProperties* pProperties -) - : mScene(pScene) - , mProperties(pProperties) -{ +FBXExporter::FBXExporter ( const aiScene* pScene, const ExportProperties* pProperties ) +: binary(false) +, mScene(pScene) +, mProperties(pProperties) +, outfile() +, connections() +, mesh_uids() +, material_uids() +, node_uids() { // will probably need to determine UIDs, connections, etc here. // basically anything that needs to be known // before we start writing sections to the stream. diff --git a/code/XGLLoader.cpp b/code/XGLLoader.cpp index 0706ffd55..196f20e90 100644 --- a/code/XGLLoader.cpp +++ b/code/XGLLoader.cpp @@ -731,11 +731,10 @@ unsigned int XGLImporter::ResolveMaterialRef(TempScope& scope) } // ------------------------------------------------------------------------------------------------ -void XGLImporter::ReadMaterial(TempScope& scope) -{ +void XGLImporter::ReadMaterial(TempScope& scope) { const unsigned int mat_id = ReadIDAttr(); - std::unique_ptr mat(new aiMaterial()); + aiMaterial *mat(new aiMaterial ); while (ReadElementUpToClosing("mat")) { const std::string& s = GetElementName(); if (s == "amb") { @@ -764,11 +763,10 @@ void XGLImporter::ReadMaterial(TempScope& scope) } } - scope.materials[mat_id] = mat.get(); - scope.materials_linear.push_back(mat.release()); + scope.materials[mat_id] = mat; + scope.materials_linear.push_back(mat); } - // ---------------------------------------------------------------------------------------------- void XGLImporter::ReadFaceVertex(const TempMesh& t, TempFace& out) { diff --git a/code/glTF2AssetWriter.inl b/code/glTF2AssetWriter.inl index 50d855aaa..75726fd08 100644 --- a/code/glTF2AssetWriter.inl +++ b/code/glTF2AssetWriter.inl @@ -744,6 +744,9 @@ namespace glTF2 { if (!(dict = FindArray(*container, d.mDictId))) { container->AddMember(StringRef(d.mDictId), Value().SetArray().Move(), mDoc.GetAllocator()); dict = FindArray(*container, d.mDictId); + if (nullptr == dict) { + return; + } } for (size_t i = 0; i < d.mObjs.size(); ++i) { diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index 40db27264..2c6bab2e0 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -643,11 +643,12 @@ void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref& meshRef, Ref buf = vertexJointAccessor->bufferView->buffer; uint8_t* arrys = new uint8_t[bytesLen]; unsigned int i = 0; + uint8_t* data = new uint8_t[s_bytesPerComp]; for ( unsigned int j = 0; j <= bytesLen; j += bytesPerComp ){ size_t len_p = offset + j; float f_value = *(float *)&buf->GetPointer()[len_p]; unsigned short c = static_cast(f_value); - uint8_t* data = new uint8_t[s_bytesPerComp]; + ::memset(data, 0, s_bytesPerComp * sizeof(uint8_t)); data = (uint8_t*)&c; memcpy(&arrys[i*s_bytesPerComp], data, s_bytesPerComp); ++i; @@ -657,6 +658,8 @@ void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref& meshRef, RefbufferView->byteLength = s_bytesLen; p.attributes.joint.push_back( vertexJointAccessor ); + delete[] arrys; + delete[] data; } Ref vertexWeightAccessor = ExportData(mAsset, skinRef->id, bufferRef, aimesh->mNumVertices, vertexWeightData, AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT);