Browse Source

Static code analysis fixes (#5447)

* Static code analysis fixes

- Fix warning in LOW

* Fix possible out of bound access.

* Add default to class declaration
Kim Kulling 1 year ago
parent
commit
3476c79801

+ 13 - 22
code/AssetLib/Irr/IRRMeshLoader.cpp

@@ -3,7 +3,7 @@
 Open Asset Import Library (assimp)
 Open Asset Import Library (assimp)
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 
 
-Copyright (c) 2006-2022, assimp team
+Copyright (c) 2006-2024, assimp team
 
 
 All rights reserved.
 All rights reserved.
 
 
@@ -69,14 +69,6 @@ static constexpr aiImporterDesc desc = {
     "xml irrmesh"
     "xml irrmesh"
 };
 };
 
 
-// ------------------------------------------------------------------------------------------------
-// Constructor to be privately used by Importer
-IRRMeshImporter::IRRMeshImporter() = default;
-
-// ------------------------------------------------------------------------------------------------
-// Destructor, private as well
-IRRMeshImporter::~IRRMeshImporter() = default;
-
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
 // Returns whether the class can handle the format of the given file.
 // Returns whether the class can handle the format of the given file.
 bool IRRMeshImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
 bool IRRMeshImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
@@ -116,8 +108,9 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
     std::unique_ptr<IOStream> file(pIOHandler->Open(pFile));
     std::unique_ptr<IOStream> file(pIOHandler->Open(pFile));
 
 
     // Check whether we can read from the file
     // Check whether we can read from the file
-    if (file == nullptr)
+    if (file == nullptr) {
         throw DeadlyImportError("Failed to open IRRMESH file ", pFile);
         throw DeadlyImportError("Failed to open IRRMESH file ", pFile);
+    }
 
 
     // Construct the irrXML parser
     // Construct the irrXML parser
     XmlParser parser;
     XmlParser parser;
@@ -148,13 +141,11 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
     // int vertexFormat = 0; // 0 = normal; 1 = 2 tcoords, 2 = tangents
     // int vertexFormat = 0; // 0 = normal; 1 = 2 tcoords, 2 = tangents
     bool useColors = false;
     bool useColors = false;
 
 
-    /*
-    ** irrmesh files have a top level <mesh> owning multiple <buffer> nodes.
-    ** Each <buffer> contains <material>, <vertices>, and <indices>
-    ** <material> tags here directly owns the material data specs
-    ** <vertices> are a vertex per line, contains position, UV1 coords, maybe UV2, normal, tangent, bitangent
-    ** <boundingbox> is ignored, I think assimp recalculates those?
-    */
+    // irrmesh files have a top level <mesh> owning multiple <buffer> nodes.
+    // Each <buffer> contains <material>, <vertices>, and <indices>
+    // <material> tags here directly owns the material data specs
+    // <vertices> are a vertex per line, contains position, UV1 coords, maybe UV2, normal, tangent, bitangent
+    // <boundingbox> is ignored, I think assimp recalculates those?
 
 
     // Parse the XML file
     // Parse the XML file
     pugi::xml_node const &meshNode = root.child("mesh");
     pugi::xml_node const &meshNode = root.child("mesh");
@@ -201,7 +192,6 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
                 // This is possible ... remove the mesh from the list and skip further reading
                 // This is possible ... remove the mesh from the list and skip further reading
                 ASSIMP_LOG_WARN("IRRMESH: Found mesh with zero vertices");
                 ASSIMP_LOG_WARN("IRRMESH: Found mesh with zero vertices");
                 releaseMaterial(&curMat);
                 releaseMaterial(&curMat);
-                // releaseMesh(&curMesh);
                 continue; // Bail out early
                 continue; // Bail out early
             };
             };
 
 
@@ -331,7 +321,8 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
 
 
             // NOTE this might explode for UTF-16 and wchars
             // NOTE this might explode for UTF-16 and wchars
             const char *sz = indicesNode.text().get();
             const char *sz = indicesNode.text().get();
-            const char *end = sz + std::strlen(sz) + 1;
+            const char *end = sz + std::strlen(sz);
+            
             // For each index loop over aiMesh faces
             // For each index loop over aiMesh faces
             while (SkipSpacesAndLineEnd(&sz, end)) {
             while (SkipSpacesAndLineEnd(&sz, end)) {
                 if (curFace >= faceEnd) {
                 if (curFace >= faceEnd) {
@@ -377,8 +368,9 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
                 }
                 }
             }
             }
             // We should be at the end of mFaces
             // We should be at the end of mFaces
-            if (curFace != faceEnd)
+            if (curFace != faceEnd) {
                 ASSIMP_LOG_ERROR("IRRMESH: Not enough indices");
                 ASSIMP_LOG_ERROR("IRRMESH: Not enough indices");
+            }
         }
         }
 
 
         // Finish processing the mesh - do some small material workarounds
         // Finish processing the mesh - do some small material workarounds
@@ -388,8 +380,7 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
             aiMaterial *mat = (aiMaterial *)curMat;
             aiMaterial *mat = (aiMaterial *)curMat;
             mat->AddProperty(&curColors[0].a, 1, AI_MATKEY_OPACITY);
             mat->AddProperty(&curColors[0].a, 1, AI_MATKEY_OPACITY);
         }
         }
-        // textMeaning = 2;
-
+        
         // end of previous buffer. A material and a mesh should be there
         // end of previous buffer. A material and a mesh should be there
         if (!curMat || !curMesh) {
         if (!curMat || !curMesh) {
             ASSIMP_LOG_ERROR("IRRMESH: A buffer must contain a mesh and a material");
             ASSIMP_LOG_ERROR("IRRMESH: A buffer must contain a mesh and a material");

+ 6 - 3
code/AssetLib/Irr/IRRMeshLoader.h

@@ -2,7 +2,7 @@
 Open Asset Import Library (assimp)
 Open Asset Import Library (assimp)
 ----------------------------------------------------------------------
 ----------------------------------------------------------------------
 
 
-Copyright (c) 2006-2022, assimp team
+Copyright (c) 2006-2024, assimp team
 
 
 All rights reserved.
 All rights reserved.
 
 
@@ -62,8 +62,11 @@ namespace Assimp {
  */
  */
 class IRRMeshImporter : public BaseImporter, public IrrlichtBase {
 class IRRMeshImporter : public BaseImporter, public IrrlichtBase {
 public:
 public:
-    IRRMeshImporter();
-    ~IRRMeshImporter() override;
+    /// @brief The class constructor.
+    IRRMeshImporter() = default;
+
+    /// @brief The class destructor.
+    ~IRRMeshImporter() override = default;
 
 
     // -------------------------------------------------------------------
     // -------------------------------------------------------------------
     /** Returns whether the class can handle the format of the given file.
     /** Returns whether the class can handle the format of the given file.

+ 7 - 7
code/AssetLib/LWS/LWSLoader.cpp

@@ -3,7 +3,7 @@
 Open Asset Import Library (assimp)
 Open Asset Import Library (assimp)
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 
 
-Copyright (c) 2006-2022, assimp team
+Copyright (c) 2006-2024, assimp team
 
 
 All rights reserved.
 All rights reserved.
 
 
@@ -155,7 +155,8 @@ const aiImporterDesc *LWSImporter::GetInfo() const {
 }
 }
 
 
 static constexpr int MagicHackNo = 150392;
 static constexpr int MagicHackNo = 150392;
-        // ------------------------------------------------------------------------------------------------
+
+// ------------------------------------------------------------------------------------------------
 // Setup configuration properties
 // Setup configuration properties
 void LWSImporter::SetupProperties(const Importer *pImp) {
 void LWSImporter::SetupProperties(const Importer *pImp) {
     // AI_CONFIG_FAVOUR_SPEED
     // AI_CONFIG_FAVOUR_SPEED
@@ -248,13 +249,12 @@ void LWSImporter::ReadEnvelope(const LWS::Element &dad, LWO::Envelope &fill) {
 // Read animation channels in the old LightWave animation format
 // Read animation channels in the old LightWave animation format
 void LWSImporter::ReadEnvelope_Old(std::list<LWS::Element>::const_iterator &it,const std::list<LWS::Element>::const_iterator &endIt, 
 void LWSImporter::ReadEnvelope_Old(std::list<LWS::Element>::const_iterator &it,const std::list<LWS::Element>::const_iterator &endIt, 
         LWS::NodeDesc &nodes, unsigned int) {
         LWS::NodeDesc &nodes, unsigned int) {
-    unsigned int num=0, sub_num=0;
     if (++it == endIt) {
     if (++it == endIt) {
         ASSIMP_LOG_ERROR("LWS: Encountered unexpected end of file while parsing object motion");
         ASSIMP_LOG_ERROR("LWS: Encountered unexpected end of file while parsing object motion");
         return;
         return;
     }
     }
 
 
-    num = strtoul10((*it).tokens[0].c_str());
+    const unsigned int num = strtoul10((*it).tokens[0].c_str());
     for (unsigned int i = 0; i < num; ++i) {
     for (unsigned int i = 0; i < num; ++i) {
         nodes.channels.emplace_back();
         nodes.channels.emplace_back();
         LWO::Envelope &envl = nodes.channels.back();
         LWO::Envelope &envl = nodes.channels.back();
@@ -266,8 +266,8 @@ void LWSImporter::ReadEnvelope_Old(std::list<LWS::Element>::const_iterator &it,c
             ASSIMP_LOG_ERROR("LWS: Encountered unexpected end of file while parsing object motion");
             ASSIMP_LOG_ERROR("LWS: Encountered unexpected end of file while parsing object motion");
             return;
             return;
         }
         }
-        sub_num = strtoul10((*it).tokens[0].c_str());
-
+        
+        const unsigned int sub_num = strtoul10((*it).tokens[0].c_str());
         for (unsigned int n = 0; n < sub_num; ++n) {
         for (unsigned int n = 0; n < sub_num; ++n) {
             if (++it == endIt) {
             if (++it == endIt) {
                 ASSIMP_LOG_ERROR("LWS: Encountered unexpected end of file while parsing object motion");
                 ASSIMP_LOG_ERROR("LWS: Encountered unexpected end of file while parsing object motion");
@@ -283,7 +283,7 @@ void LWSImporter::ReadEnvelope_Old(std::list<LWS::Element>::const_iterator &it,c
             fast_atoreal_move<float>((*it).tokens[0].c_str(), f);
             fast_atoreal_move<float>((*it).tokens[0].c_str(), f);
             key.time = f;
             key.time = f;
 
 
-            envl.keys.push_back(key);
+            envl.keys.emplace_back(key);
         }
         }
     }
     }
 }
 }