fix some static-analysis findings.

pull/1797/head
Kim Kulling 2018-02-13 20:36:22 +01:00
parent 78173177e8
commit ccbcaa2ee8
8 changed files with 65 additions and 75 deletions

View File

@ -60,9 +60,9 @@ namespace Assimp {
* @param in Input mesh * @param in Input mesh
* @return Hash. * @return Hash.
*/ */
inline uint64_t GetMeshHash(aiMesh* in) inline
{ uint64_t GetMeshHash(aiMesh* in) {
ai_assert(NULL != in); ai_assert(nullptr != in);
// ... get an unique value representing the vertex format of the mesh // ... get an unique value representing the vertex format of the mesh
const unsigned int fhash = GetMeshVFormatUnique(in); const unsigned int fhash = GetMeshVFormatUnique(in);
@ -78,14 +78,14 @@ inline uint64_t GetMeshHash(aiMesh* in)
/** @brief Perform a component-wise comparison of two arrays /** @brief Perform a component-wise comparison of two arrays
* *
* @param first First array * @param first First array
* @param second Second aray * @param second Second array
* @param size Size of both arrays * @param size Size of both arrays
* @param e Epsilon * @param e Epsilon
* @return true if the arrays are identical * @return true if the arrays are identical
*/ */
inline bool CompareArrays(const aiVector3D* first, const aiVector3D* second, inline
unsigned int size, float e) bool CompareArrays(const aiVector3D* first, const aiVector3D* second,
{ unsigned int size, float e) {
for (const aiVector3D* end = first+size; first != end; ++first,++second) { for (const aiVector3D* end = first+size; first != end; ++first,++second) {
if ( (*first - *second).SquareLength() >= e) if ( (*first - *second).SquareLength() >= e)
return false; return false;

View File

@ -731,17 +731,22 @@ enum MeshAttribute {
TexCoord TexCoord
}; };
static const std::string PosToken = "position";
static const std::string ColToken = "color";
static const std::string NormalToken = "normal";
static const std::string TexCoordToken = "texcoord";
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
static MeshAttribute getAttributeByName( const char *attribName ) { static MeshAttribute getAttributeByName( const char *attribName ) {
ai_assert( nullptr != attribName ); ai_assert( nullptr != attribName );
if ( 0 == strncmp( "position", attribName, strlen( "position" ) ) ) { if ( 0 == strncmp( PosToken.c_str(), attribName, PosToken.size() ) ) {
return Position; return Position;
} else if ( 0 == strncmp( "color", attribName, strlen( "color" ) ) ) { } else if ( 0 == strncmp( ColToken.c_str(), attribName, ColToken.size() ) ) {
return Color; return Color;
} else if( 0 == strncmp( "normal", attribName, strlen( "normal" ) ) ) { } else if( 0 == strncmp( NormalToken.c_str(), attribName, NormalToken.size() ) ) {
return Normal; return Normal;
} else if( 0 == strncmp( "texcoord", attribName, strlen( "texcoord" ) ) ) { } else if( 0 == strncmp( TexCoordToken.c_str(), attribName, TexCoordToken.size() ) ) {
return TexCoord; return TexCoord;
} }
@ -1098,17 +1103,15 @@ void OpenGEXImporter::handleParamNode( ODDLParser::DDLNode *node, aiScene * /*pS
return; return;
} }
const float floatVal( val->getFloat() ); const float floatVal( val->getFloat() );
if ( prop->m_value != nullptr ) {
if ( 0 == ASSIMP_strincmp( "fov", prop->m_value->getString(), 3 ) ) { if ( 0 == ASSIMP_strincmp( "fov", prop->m_value->getString(), 3 ) ) {
m_currentCamera->mHorizontalFOV = floatVal; m_currentCamera->mHorizontalFOV = floatVal;
} else if ( 0 == ASSIMP_strincmp( "near", prop->m_value->getString(), 3 ) ) { } else if ( 0 == ASSIMP_strincmp( "near", prop->m_value->getString(), 4 ) ) {
m_currentCamera->mClipPlaneNear = floatVal; m_currentCamera->mClipPlaneNear = floatVal;
} else if ( 0 == ASSIMP_strincmp( "far", prop->m_value->getString(), 3 ) ) { } else if ( 0 == ASSIMP_strincmp( "far", prop->m_value->getString(), 3 ) ) {
m_currentCamera->mClipPlaneFar = floatVal; m_currentCamera->mClipPlaneFar = floatVal;
} }
} }
} }
}
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleAttenNode( ODDLParser::DDLNode *node, aiScene * /*pScene*/ ) { void OpenGEXImporter::handleAttenNode( ODDLParser::DDLNode *node, aiScene * /*pScene*/ ) {

View File

@ -1279,6 +1279,7 @@ void SceneCombiner::Copy(aiMetadata** _dest, const aiMetadata* src) {
break; break;
default: default:
ai_assert(false); ai_assert(false);
break;
} }
} }
} }

View File

@ -294,7 +294,7 @@ void SpatialSort::FindIdenticalPositions( const aiVector3D& pPosition,
index++; index++;
// Now start iterating from there until the first position lays outside of the distance range. // Now start iterating from there until the first position lays outside of the distance range.
// Add all positions inside the distance range within the tolerance to the result aray // Add all positions inside the distance range within the tolerance to the result array
std::vector<Entry>::const_iterator it = mPositions.begin() + index; std::vector<Entry>::const_iterator it = mPositions.begin() + index;
while( ToBinary(it->mDistance) < maxDistBinary) while( ToBinary(it->mDistance) < maxDistBinary)
{ {

View File

@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "VertexTriangleAdjacency.h" #include "VertexTriangleAdjacency.h"
#include <assimp/mesh.h> #include <assimp/mesh.h>
using namespace Assimp; using namespace Assimp;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -60,8 +59,8 @@ VertexTriangleAdjacency::VertexTriangleAdjacency(aiFace *pcFaces,
// compute the number of referenced vertices if it wasn't specified by the caller // compute the number of referenced vertices if it wasn't specified by the caller
const aiFace* const pcFaceEnd = pcFaces + iNumFaces; const aiFace* const pcFaceEnd = pcFaces + iNumFaces;
if (!iNumVertices) { if (!iNumVertices) {
for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) { for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) {
ai_assert( nullptr != pcFace );
ai_assert(3 == pcFace->mNumIndices); ai_assert(3 == pcFace->mNumIndices);
iNumVertices = std::max(iNumVertices,pcFace->mIndices[0]); iNumVertices = std::max(iNumVertices,pcFace->mIndices[0]);
iNumVertices = std::max(iNumVertices,pcFace->mIndices[1]); iNumVertices = std::max(iNumVertices,pcFace->mIndices[1]);
@ -69,19 +68,18 @@ VertexTriangleAdjacency::VertexTriangleAdjacency(aiFace *pcFaces,
} }
} }
this->iNumVertices = iNumVertices; mNumVertices = iNumVertices;
unsigned int* pi; unsigned int* pi;
// allocate storage // allocate storage
if (bComputeNumTriangles) { if (bComputeNumTriangles) {
pi = mLiveTriangles = new unsigned int[iNumVertices+1]; pi = mLiveTriangles = new unsigned int[iNumVertices+1];
memset(mLiveTriangles,0,sizeof(unsigned int)*(iNumVertices+1)); ::memset(mLiveTriangles,0,sizeof(unsigned int)*(iNumVertices+1));
mOffsetTable = new unsigned int[iNumVertices+2]+1; mOffsetTable = new unsigned int[iNumVertices+2]+1;
} } else {
else {
pi = mOffsetTable = new unsigned int[iNumVertices+2]+1; pi = mOffsetTable = new unsigned int[iNumVertices+2]+1;
memset(mOffsetTable,0,sizeof(unsigned int)*(iNumVertices+1)); ::memset(mOffsetTable,0,sizeof(unsigned int)*(iNumVertices+1));
mLiveTriangles = NULL; // important, otherwise the d'tor would crash mLiveTriangles = NULL; // important, otherwise the d'tor would crash
} }
@ -90,8 +88,7 @@ VertexTriangleAdjacency::VertexTriangleAdjacency(aiFace *pcFaces,
*piEnd++ = 0u; *piEnd++ = 0u;
// first pass: compute the number of faces referencing each vertex // first pass: compute the number of faces referencing each vertex
for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) {
{
pi[pcFace->mIndices[0]]++; pi[pcFace->mIndices[0]]++;
pi[pcFace->mIndices[1]]++; pi[pcFace->mIndices[1]]++;
pi[pcFace->mIndices[2]]++; pi[pcFace->mIndices[2]]++;

View File

@ -60,10 +60,8 @@ namespace Assimp {
* @note Although it is called #VertexTriangleAdjacency, the current version does also * @note Although it is called #VertexTriangleAdjacency, the current version does also
* support arbitrary polygons. */ * support arbitrary polygons. */
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
class ASSIMP_API VertexTriangleAdjacency class ASSIMP_API VertexTriangleAdjacency {
{
public: public:
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** @brief Construction from an existing index buffer /** @brief Construction from an existing index buffer
* @param pcFaces Index buffer * @param pcFaces Index buffer
@ -77,39 +75,30 @@ public:
unsigned int iNumVertices = 0, unsigned int iNumVertices = 0,
bool bComputeNumTriangles = true); bool bComputeNumTriangles = true);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** @brief Destructor */ /** @brief Destructor */
~VertexTriangleAdjacency(); ~VertexTriangleAdjacency();
public:
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** @brief Get all triangles adjacent to a vertex /** @brief Get all triangles adjacent to a vertex
* @param iVertIndex Index of the vertex * @param iVertIndex Index of the vertex
* @return A pointer to the adjacency list. */ * @return A pointer to the adjacency list. */
unsigned int* GetAdjacentTriangles(unsigned int iVertIndex) const unsigned int* GetAdjacentTriangles(unsigned int iVertIndex) const {
{ ai_assert(iVertIndex < mNumVertices);
ai_assert(iVertIndex < iNumVertices);
return &mAdjacencyTable[ mOffsetTable[iVertIndex]]; return &mAdjacencyTable[ mOffsetTable[iVertIndex]];
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** @brief Get the number of triangles that are referenced by /** @brief Get the number of triangles that are referenced by
* a vertex. This function returns a reference that can be modified * a vertex. This function returns a reference that can be modified
* @param iVertIndex Index of the vertex * @param iVertIndex Index of the vertex
* @return Number of referenced triangles */ * @return Number of referenced triangles */
unsigned int& GetNumTrianglesPtr(unsigned int iVertIndex) unsigned int& GetNumTrianglesPtr(unsigned int iVertIndex) {
{ ai_assert( iVertIndex < mNumVertices );
ai_assert(iVertIndex < iNumVertices && NULL != mLiveTriangles); ai_assert( nullptr != mLiveTriangles );
return mLiveTriangles[iVertIndex]; return mLiveTriangles[iVertIndex];
} }
public:
//! Offset table //! Offset table
unsigned int* mOffsetTable; unsigned int* mOffsetTable;
@ -120,9 +109,9 @@ public:
unsigned int* mLiveTriangles; unsigned int* mLiveTriangles;
//! Debug: Number of referenced vertices //! Debug: Number of referenced vertices
unsigned int iNumVertices; unsigned int mNumVertices;
}; };
}
} //! ns Assimp
#endif // !! AI_VTADJACENCY_H_INC #endif // !! AI_VTADJACENCY_H_INC

View File

@ -248,9 +248,9 @@ bool IOStreamBuffer<T>::getNextDataLine( std::vector<T> &buffer, T continuationT
} }
} }
bool continuationFound( false ), endOfDataLine( false ); bool continuationFound( false );
size_t i = 0; size_t i = 0;
while ( !endOfDataLine ) { for( ;; ) {
if ( continuationToken == m_cache[ m_cachePos ] ) { if ( continuationToken == m_cache[ m_cachePos ] ) {
continuationFound = true; continuationFound = true;
++m_cachePos; ++m_cachePos;