Merge pull request #1007 from wise86-android/coverity_scan_fix

Coverity scan fix
pull/2286/head
Kim Kulling 2016-09-25 11:52:07 +02:00 committed by GitHub
commit 64273d58e3
15 changed files with 72 additions and 54 deletions

View File

@ -806,4 +806,4 @@ void DNA::RegisterConverters() {
} }
#endif ASSIMP_BUILD_NO_BLEND_IMPORTER #endif //ASSIMP_BUILD_NO_BLEND_IMPORTER

View File

@ -1394,9 +1394,9 @@ unsigned int Converter::ConvertMeshMultiMaterial( const MeshGeometry& mesh, cons
// allocate tangents, binormals. // allocate tangents, binormals.
const std::vector<aiVector3D>& tangents = mesh.GetTangents(); const std::vector<aiVector3D>& tangents = mesh.GetTangents();
const std::vector<aiVector3D>* binormals = &mesh.GetBinormals(); const std::vector<aiVector3D>* binormals = &mesh.GetBinormals();
std::vector<aiVector3D> tempBinormals;
if ( tangents.size() ) { if ( tangents.size() ) {
std::vector<aiVector3D> tempBinormals;
if ( !binormals->size() ) { if ( !binormals->size() ) {
if ( normals.size() ) { if ( normals.size() ) {
// XXX this computes the binormals for the entire mesh, not only // XXX this computes the binormals for the entire mesh, not only

View File

@ -127,8 +127,7 @@ void HMPImporter::InternReadFile( const std::string& pFile,
throw DeadlyImportError( "HMP File is too small."); throw DeadlyImportError( "HMP File is too small.");
// Allocate storage and copy the contents of the file to a memory buffer // Allocate storage and copy the contents of the file to a memory buffer
std::vector<uint8_t> buffer(fileSize); mBuffer = new uint8_t[fileSize];
mBuffer = &buffer[0];
file->Read( (void*)mBuffer, 1, fileSize); file->Read( (void*)mBuffer, 1, fileSize);
iFileSize = (unsigned int)fileSize; iFileSize = (unsigned int)fileSize;
@ -174,7 +173,9 @@ void HMPImporter::InternReadFile( const std::string& pFile,
// Set the AI_SCENE_FLAGS_TERRAIN bit // Set the AI_SCENE_FLAGS_TERRAIN bit
pScene->mFlags |= AI_SCENE_FLAGS_TERRAIN; pScene->mFlags |= AI_SCENE_FLAGS_TERRAIN;
// File buffer destructs automatically now delete[] mBuffer;
mBuffer= nullptr;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -449,11 +450,13 @@ void HMPImporter::ReadFirstSkin(unsigned int iNumSkins, const unsigned char* szC
// read the type of the skin ... // read the type of the skin ...
// sometimes we need to skip 12 bytes here, I don't know why ... // sometimes we need to skip 12 bytes here, I don't know why ...
uint32_t iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t); uint32_t iType = *((uint32_t*)szCursor);
szCursor += sizeof(uint32_t);
if (0 == iType) if (0 == iType)
{ {
szCursor += sizeof(uint32_t) * 2; szCursor += sizeof(uint32_t) * 2;
iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t); iType = *((uint32_t*)szCursor);
szCursor += sizeof(uint32_t);
if (!iType) if (!iType)
throw DeadlyImportError("Unable to read HMP7 skin chunk"); throw DeadlyImportError("Unable to read HMP7 skin chunk");

View File

@ -269,14 +269,15 @@ void IRRImporter::CopyMaterial(std::vector<aiMaterial*>& materials,
if (UINT_MAX == defMatIdx) if (UINT_MAX == defMatIdx)
{ {
defMatIdx = (unsigned int)materials.size(); defMatIdx = (unsigned int)materials.size();
aiMaterial* mat = new aiMaterial(); //TODO: add this materials to someone?
/*aiMaterial* mat = new aiMaterial();
aiString s; aiString s;
s.Set(AI_DEFAULT_MATERIAL_NAME); s.Set(AI_DEFAULT_MATERIAL_NAME);
mat->AddProperty(&s,AI_MATKEY_NAME); mat->AddProperty(&s,AI_MATKEY_NAME);
aiColor3D c(0.6f,0.6f,0.6f); aiColor3D c(0.6f,0.6f,0.6f);
mat->AddProperty(&c,1,AI_MATKEY_COLOR_DIFFUSE); mat->AddProperty(&c,1,AI_MATKEY_COLOR_DIFFUSE);*/
} }
mesh->mMaterialIndex = defMatIdx; mesh->mMaterialIndex = defMatIdx;
return; return;

View File

@ -116,14 +116,18 @@ const aiImporterDesc* IRRMeshImporter::GetInfo () const
return &desc; return &desc;
} }
static void releaseMaterial( aiMaterial *mat ) { static void releaseMaterial( aiMaterial **mat ) {
delete mat; if(*mat!= nullptr) {
mat = nullptr; delete *mat;
*mat = nullptr;
}
} }
static void releaseMesh( aiMesh *mesh ) { static void releaseMesh( aiMesh **mesh ) {
delete mesh; if (*mesh != nullptr){
mesh = nullptr; delete *mesh;
*mesh = nullptr;
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -148,8 +152,8 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
meshes.reserve(5); meshes.reserve(5);
// temporary data - current mesh buffer // temporary data - current mesh buffer
aiMaterial* curMat = NULL; aiMaterial* curMat = nullptr;
aiMesh* curMesh = NULL; aiMesh* curMesh = nullptr;
unsigned int curMatFlags = 0; unsigned int curMatFlags = 0;
std::vector<aiVector3D> curVertices,curNormals,curTangents,curBitangents; std::vector<aiVector3D> curVertices,curNormals,curTangents,curBitangents;
@ -170,14 +174,14 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
// 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) {
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material"); DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
releaseMaterial( curMat ); releaseMaterial( &curMat );
releaseMesh( curMesh ); releaseMesh( &curMesh );
} else { } else {
materials.push_back(curMat); materials.push_back(curMat);
meshes.push_back(curMesh); meshes.push_back(curMesh);
} }
curMat = NULL; curMat = nullptr;
curMesh = NULL; curMesh = nullptr;
curVertices.clear(); curVertices.clear();
curColors.clear(); curColors.clear();
@ -192,7 +196,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
if (!ASSIMP_stricmp(reader->getNodeName(),"material")) { if (!ASSIMP_stricmp(reader->getNodeName(),"material")) {
if (curMat) { if (curMat) {
DefaultLogger::get()->warn("IRRMESH: Only one material description per buffer, please"); DefaultLogger::get()->warn("IRRMESH: Only one material description per buffer, please");
releaseMaterial( curMat ); releaseMaterial( &curMat );
} }
curMat = ParseMaterial(curMatFlags); curMat = ParseMaterial(curMatFlags);
} }
@ -204,8 +208,8 @@ 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
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero vertices"); DefaultLogger::get()->warn("IRRMESH: Found mesh with zero vertices");
releaseMaterial( curMat ); releaseMaterial( &curMat );
releaseMesh( curMesh ); releaseMesh( &curMesh );
textMeaning = 0; textMeaning = 0;
continue; continue;
} }
@ -248,7 +252,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
vertexFormat = 2; vertexFormat = 2;
} }
else if (ASSIMP_stricmp("standard", t)) { else if (ASSIMP_stricmp("standard", t)) {
releaseMaterial( curMat ); releaseMaterial( &curMat );
DefaultLogger::get()->warn("IRRMESH: Unknown vertex format"); DefaultLogger::get()->warn("IRRMESH: Unknown vertex format");
} }
else vertexFormat = 0; else vertexFormat = 0;
@ -256,7 +260,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
} }
else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) { else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) {
if (curVertices.empty() && curMat) { if (curVertices.empty() && curMat) {
releaseMaterial( curMat ); releaseMaterial( &curMat );
throw DeadlyImportError("IRRMESH: indices must come after vertices"); throw DeadlyImportError("IRRMESH: indices must come after vertices");
} }
@ -272,10 +276,10 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero indices"); DefaultLogger::get()->warn("IRRMESH: Found mesh with zero indices");
// mesh - away // mesh - away
releaseMesh( curMesh ); releaseMesh( &curMesh );
// material - away // material - away
releaseMaterial( curMat ); releaseMaterial( &curMat );
textMeaning = 0; textMeaning = 0;
continue; continue;
@ -487,8 +491,8 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
if (curMat || curMesh) { if (curMat || curMesh) {
if ( !curMat || !curMesh) { if ( !curMat || !curMesh) {
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material"); DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
releaseMaterial( curMat ); releaseMaterial( &curMat );
releaseMesh( curMesh ); releaseMesh( &curMesh );
} }
else { else {
materials.push_back(curMat); materials.push_back(curMat);

View File

@ -1058,8 +1058,6 @@ void LWOImporter::LoadLWO2VertexMap(unsigned int length, bool perPoly)
LWO::PointList& pointList = mCurLayer->mTempPoints; LWO::PointList& pointList = mCurLayer->mTempPoints;
LWO::ReferrerList& refList = mCurLayer->mPointReferrers; LWO::ReferrerList& refList = mCurLayer->mPointReferrers;
float temp[4];
const unsigned int numPoints = (unsigned int)pointList.size(); const unsigned int numPoints = (unsigned int)pointList.size();
const unsigned int numFaces = (unsigned int)list.size(); const unsigned int numFaces = (unsigned int)list.size();
@ -1123,10 +1121,12 @@ void LWOImporter::LoadLWO2VertexMap(unsigned int length, bool perPoly)
} }
} }
} }
std::unique_ptr<float[]> temp(new float[type]);
for (unsigned int l = 0; l < type;++l) for (unsigned int l = 0; l < type;++l)
temp[l] = GetF4(); temp[l] = GetF4();
DoRecursiveVMAPAssignment(base,type,idx, temp); DoRecursiveVMAPAssignment(base,type,idx, temp.get());
mFileBuffer += diff; mFileBuffer += diff;
} }
} }

View File

@ -172,8 +172,7 @@ void MDLImporter::InternReadFile( const std::string& pFile,
} }
// Allocate storage and copy the contents of the file to a memory buffer // Allocate storage and copy the contents of the file to a memory buffer
std::vector<unsigned char> buffer(iFileSize+1); mBuffer =new unsigned char[iFileSize+1];
mBuffer = &buffer[0];
file->Read( (void*)mBuffer, 1, iFileSize); file->Read( (void*)mBuffer, 1, iFileSize);
// Append a binary zero to the end of the buffer. // Append a binary zero to the end of the buffer.
@ -239,7 +238,8 @@ void MDLImporter::InternReadFile( const std::string& pFile,
0.f,0.f,1.f,0.f,0.f,-1.f,0.f,0.f,0.f,0.f,0.f,1.f); 0.f,0.f,1.f,0.f,0.f,-1.f,0.f,0.f,0.f,0.f,0.f,1.f);
// delete the file buffer and cleanup // delete the file buffer and cleanup
AI_DEBUG_INVALIDATE_PTR(mBuffer); delete [] mBuffer;
mBuffer= nullptr;
AI_DEBUG_INVALIDATE_PTR(pIOHandler); AI_DEBUG_INVALIDATE_PTR(pIOHandler);
AI_DEBUG_INVALIDATE_PTR(pScene); AI_DEBUG_INVALIDATE_PTR(pScene);
} }
@ -1557,7 +1557,7 @@ void MDLImporter::InternReadFile_3DGS_MDL7( )
} else { } else {
pcNode->mName.length = ::strlen(szBuffer); pcNode->mName.length = ::strlen(szBuffer);
} }
::strcpy(pcNode->mName.data,szBuffer); ::strncpy(pcNode->mName.data,szBuffer,MAXLEN);
++p; ++p;
} }
} }

View File

@ -488,7 +488,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
unsigned int iWidth, unsigned int iWidth,
unsigned int iHeight) unsigned int iHeight)
{ {
aiTexture* pcNew = NULL; aiTexture* pcNew = nullptr;
// get the type of the skin // get the type of the skin
unsigned int iMasked = (unsigned int)(iType & 0xF); unsigned int iMasked = (unsigned int)(iType & 0xF);
@ -522,7 +522,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
memcpy(pcNew->pcData,szCurrent,pcNew->mWidth); memcpy(pcNew->pcData,szCurrent,pcNew->mWidth);
szCurrent += iWidth; szCurrent += iWidth;
} }
if (0x7 == iMasked) else if (0x7 == iMasked)
{ {
// ***** REFERENCE TO EXTERNAL FILE ***** // ***** REFERENCE TO EXTERNAL FILE *****
if (1 != iHeight) if (1 != iHeight)
@ -546,6 +546,9 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
else if (iMasked || !iType || (iType && iWidth && iHeight)) else if (iMasked || !iType || (iType && iWidth && iHeight))
{ {
// ***** STANDARD COLOR TEXTURE ***** // ***** STANDARD COLOR TEXTURE *****
if(pcNew!= nullptr)
delete pcNew;
pcNew = new aiTexture(); pcNew = new aiTexture();
if (!iHeight || !iWidth) if (!iHeight || !iWidth)
{ {

View File

@ -168,6 +168,8 @@ bool MakeVerboseFormatProcess::MakeVerboseFormat(aiMesh* pcMesh)
} }
} }
// build output vertex weights // build output vertex weights
for (unsigned int i = 0;i < pcMesh->mNumBones;++i) for (unsigned int i = 0;i < pcMesh->mNumBones;++i)
{ {
@ -177,11 +179,11 @@ bool MakeVerboseFormatProcess::MakeVerboseFormat(aiMesh* pcMesh)
aiVertexWeight *weightToCopy = &( newWeights[i][0] ); aiVertexWeight *weightToCopy = &( newWeights[i][0] );
memcpy(pcMesh->mBones[i]->mWeights, weightToCopy, memcpy(pcMesh->mBones[i]->mWeights, weightToCopy,
sizeof(aiVertexWeight) * newWeights[i].size()); sizeof(aiVertexWeight) * newWeights[i].size());
delete[] newWeights;
} else { } else {
pcMesh->mBones[i]->mWeights = NULL; pcMesh->mBones[i]->mWeights = NULL;
} }
} }
delete[] newWeights;
// delete the old members // delete the old members
delete[] pcMesh->mVertices; delete[] pcMesh->mVertices;

View File

@ -257,7 +257,8 @@ void NDOImporter::InternReadFile( const std::string& pFile,
} }
aiMesh* mesh = new aiMesh(); aiMesh* mesh = new aiMesh();
aiFace* faces = mesh->mFaces = new aiFace[mesh->mNumFaces=face_table.size()]; mesh->mNumFaces=face_table.size();
aiFace* faces = mesh->mFaces = new aiFace[mesh->mNumFaces];
vertices.clear(); vertices.clear();
vertices.reserve(4 * face_table.size()); // arbitrarily chosen vertices.reserve(4 * face_table.size()); // arbitrarily chosen
@ -298,7 +299,8 @@ void NDOImporter::InternReadFile( const std::string& pFile,
pScene->mMeshes[pScene->mNumMeshes] = mesh; pScene->mMeshes[pScene->mNumMeshes] = mesh;
(nd->mMeshes = new unsigned int[nd->mNumMeshes=1])[0]=pScene->mNumMeshes++; (nd->mMeshes = new unsigned int[nd->mNumMeshes=1])[0]=pScene->mNumMeshes++;
} }else
delete mesh;
} }
} }

View File

@ -660,7 +660,7 @@ void SMDImporter::CreateOutputMaterials()
if (aszTextures[iMat].length()) if (aszTextures[iMat].length())
{ {
::strcpy(szName.data, aszTextures[iMat].c_str() ); ::strncpy(szName.data, aszTextures[iMat].c_str(),MAXLEN );
szName.length = aszTextures[iMat].length(); szName.length = aszTextures[iMat].length();
pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0)); pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0));
} }

View File

@ -513,7 +513,7 @@ std::string XFileExporter::toXFileString(aiString &name)
return str; return str;
} }
void XFileExporter::writePath(aiString path) void XFileExporter::writePath(const aiString &path)
{ {
std::string str = std::string(path.C_Str()); std::string str = std::string(path.C_Str());
BaseImporter::ConvertUTF8toISO8859_1(str); BaseImporter::ConvertUTF8toISO8859_1(str);

View File

@ -107,7 +107,7 @@ protected:
const ExportProperties* mProperties; const ExportProperties* mProperties;
/// write a path /// write a path
void writePath(aiString path); void writePath(const aiString &path);
/// The IOSystem for output /// The IOSystem for output
IOSystem* mIOSystem; IOSystem* mIOSystem;

View File

@ -105,13 +105,13 @@ struct aiMetadataEntry
* Helper functions to get the aiType enum entry for a type * Helper functions to get the aiType enum entry for a type
*/ */
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
inline aiMetadataType GetAiType( bool ) { return AI_BOOL; } inline aiMetadataType GetAiType( const bool& ) { return AI_BOOL; }
inline aiMetadataType GetAiType( int ) { return AI_INT; } inline aiMetadataType GetAiType( const int& ) { return AI_INT; }
inline aiMetadataType GetAiType( uint64_t ) { return AI_UINT64; } inline aiMetadataType GetAiType( const uint64_t& ) { return AI_UINT64; }
inline aiMetadataType GetAiType( float ) { return AI_FLOAT; } inline aiMetadataType GetAiType( const float& ) { return AI_FLOAT; }
inline aiMetadataType GetAiType( double ) { return AI_DOUBLE; } inline aiMetadataType GetAiType( const double& ) { return AI_DOUBLE; }
inline aiMetadataType GetAiType( aiString ) { return AI_AISTRING; } inline aiMetadataType GetAiType( const aiString& ) { return AI_AISTRING; }
inline aiMetadataType GetAiType( aiVector3D ) { return AI_AIVECTOR3D; } inline aiMetadataType GetAiType( const aiVector3D& ) { return AI_AIVECTOR3D; }

View File

@ -48,10 +48,13 @@ class BlenderIntermediateTest : public ::testing::Test {
// empty // empty
}; };
#define NAME_1 "name1"
#define NAME_2 "name2"
TEST_F( BlenderIntermediateTest,ConversionData_ObjectCompareTest ) { TEST_F( BlenderIntermediateTest,ConversionData_ObjectCompareTest ) {
Object obj1, obj2; Object obj1, obj2;
strncpy( obj1.id.name, "name1", 5 ); strncpy( obj1.id.name, NAME_1, sizeof(NAME_1) );
strncpy( obj2.id.name, "name2", 5 ); strncpy( obj2.id.name, NAME_2, sizeof(NAME_2) );
Blender::ObjectCompare cmp_false; Blender::ObjectCompare cmp_false;
bool res( cmp_false( &obj1, &obj2 ) ); bool res( cmp_false( &obj1, &obj2 ) );
EXPECT_FALSE( res ); EXPECT_FALSE( res );