Browse Source

Coverity-findings

Kim Kulling 6 năm trước cách đây
mục cha
commit
4c6db68d34
5 tập tin đã thay đổi với 36 bổ sung17 xóa
  1. 16 3
      code/FBXExportNode.h
  2. 9 7
      code/FBXExporter.cpp
  3. 4 6
      code/XGLLoader.cpp
  4. 3 0
      code/glTF2AssetWriter.inl
  5. 4 1
      code/glTF2Exporter.cpp

+ 16 - 3
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 <typename... More>
     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

+ 9 - 7
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.

+ 4 - 6
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<aiMaterial> 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)
 {

+ 3 - 0
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) {

+ 4 - 1
code/glTF2Exporter.cpp

@@ -643,11 +643,12 @@ void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref<Mesh>& meshRef, Ref<Buf
         Ref<Buffer> 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<unsigned short>(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<Mesh>& meshRef, Ref<Buf
         vertexJointAccessor->bufferView->byteLength = s_bytesLen;
 
         p.attributes.joint.push_back( vertexJointAccessor );
+        delete[] arrys;
+        delete[] data;
     }
 
     Ref<Accessor> vertexWeightAccessor = ExportData(mAsset, skinRef->id, bufferRef, aimesh->mNumVertices, vertexWeightData, AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT);