Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static code analysis #2674

Closed
wants to merge 10 commits into from
30 changes: 17 additions & 13 deletions code/3DS/3DSConverter.cpp
Expand Up @@ -5,8 +5,6 @@ Open Asset Import Library (assimp)

Copyright (c) 2006-2019, assimp team



All rights reserved.

Redistribution and use of this software in source and binary forms,
Expand Down Expand Up @@ -61,8 +59,7 @@ static const unsigned int NotSet = 0xcdcdcdcd;

// ------------------------------------------------------------------------------------------------
// Setup final material indices, generae a default material if necessary
void Discreet3DSImporter::ReplaceDefaultMaterial()
{
void Discreet3DSImporter::ReplaceDefaultMaterial() {
// Try to find an existing material that matches the
// typical default material setting:
// - no textures
Expand Down Expand Up @@ -276,18 +273,17 @@ void Discreet3DSImporter::ConvertMaterial(D3DS::Material& oldMat,
mat.AddProperty<ai_real>( &oldMat.mBumpHeight,1,AI_MATKEY_BUMPSCALING);

// Two sided rendering?
if (oldMat.mTwoSided)
{
if (oldMat.mTwoSided) {
int i = 1;
mat.AddProperty<int>(&i,1,AI_MATKEY_TWOSIDED);
}

// Shading mode
aiShadingMode eShading = aiShadingMode_NoShading;
switch (oldMat.mShading)
{
switch (oldMat.mShading) {
case D3DS::Discreet3DS::Flat:
eShading = aiShadingMode_Flat; break;
eShading = aiShadingMode_Flat;
break;

// I don't know what "Wire" shading should be,
// assume it is simple lambertian diffuse shading
Expand All @@ -297,22 +293,30 @@ void Discreet3DSImporter::ConvertMaterial(D3DS::Material& oldMat,
unsigned int iWire = 1;
mat.AddProperty<int>( (int*)&iWire,1,AI_MATKEY_ENABLE_WIREFRAME);
}
break;

case D3DS::Discreet3DS::Gouraud:
eShading = aiShadingMode_Gouraud; break;
eShading = aiShadingMode_Gouraud;
break;

// assume cook-torrance shading for metals.
case D3DS::Discreet3DS::Phong :
eShading = aiShadingMode_Phong; break;
eShading = aiShadingMode_Phong;
break;

case D3DS::Discreet3DS::Metal :
eShading = aiShadingMode_CookTorrance; break;
eShading = aiShadingMode_CookTorrance;
break;

// FIX to workaround a warning with GCC 4 who complained
// about a missing case Blinn: here - Blinn isn't a valid
// value in the 3DS Loader, it is just needed for ASE
case D3DS::Discreet3DS::Blinn :
eShading = aiShadingMode_Blinn; break;
eShading = aiShadingMode_Blinn;
break;

default:
break;
}
int eShading_ = static_cast<int>(eShading);
mat.AddProperty<int>(&eShading_, 1, AI_MATKEY_SHADING_MODEL);
Expand Down
11 changes: 7 additions & 4 deletions code/3DS/3DSLoader.cpp
Expand Up @@ -707,10 +707,11 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent)
mLastNodeIndex++;
}
else if(hierarchy >= mLastNodeIndex) {

// place it at the current position in the hierarchy
mCurrentNode->push_back(pcNode);
mLastNodeIndex = hierarchy;
if (nullptr != mCurrentNode) {
// place it at the current position in the hierarchy
mCurrentNode->push_back(pcNode);
mLastNodeIndex = hierarchy;
}
}
else {
// need to go back to the specified position in the hierarchy.
Expand Down Expand Up @@ -1376,6 +1377,7 @@ void Discreet3DSImporter::ParseColorChunk( aiColor3D* out, bool acceptPercent )
{
case Discreet3DS::CHUNK_LINRGBF:
bGamma = true;
break;

case Discreet3DS::CHUNK_RGBF:
if (sizeof(float) * 3 > diff) {
Expand All @@ -1389,6 +1391,7 @@ void Discreet3DSImporter::ParseColorChunk( aiColor3D* out, bool acceptPercent )

case Discreet3DS::CHUNK_LINRGBB:
bGamma = true;
break;
case Discreet3DS::CHUNK_RGBB:
{
if ( sizeof( char ) * 3 > diff ) {
Expand Down
16 changes: 11 additions & 5 deletions code/ASE/ASELoader.cpp
Expand Up @@ -883,11 +883,14 @@ void ASEImporter::ConvertMaterial(ASE::Material& mat)
switch (mat.mShading)
{
case D3DS::Discreet3DS::Flat:
eShading = aiShadingMode_Flat; break;
eShading = aiShadingMode_Flat;
break;
case D3DS::Discreet3DS::Phong :
eShading = aiShadingMode_Phong; break;
eShading = aiShadingMode_Phong;
break;
case D3DS::Discreet3DS::Blinn :
eShading = aiShadingMode_Blinn; break;
eShading = aiShadingMode_Blinn;
break;

// I don't know what "Wire" shading should be,
// assume it is simple lambertian diffuse (L dot N) shading
Expand All @@ -897,10 +900,13 @@ void ASEImporter::ConvertMaterial(ASE::Material& mat)
unsigned int iWire = 1;
mat.pcInstance->AddProperty<int>( (int*)&iWire,1,AI_MATKEY_ENABLE_WIREFRAME);
}
break;
case D3DS::Discreet3DS::Gouraud:
eShading = aiShadingMode_Gouraud; break;
eShading = aiShadingMode_Gouraud;
break;
case D3DS::Discreet3DS::Metal :
eShading = aiShadingMode_CookTorrance; break;
eShading = aiShadingMode_CookTorrance;
break;
}
mat.pcInstance->AddProperty<int>( (int*)&eShading,1,AI_MATKEY_SHADING_MODEL);

Expand Down
12 changes: 4 additions & 8 deletions code/ASE/ASEParser.cpp
Expand Up @@ -5,8 +5,6 @@ Open Asset Import Library (assimp)

Copyright (c) 2006-2019, assimp team



All rights reserved.

Redistribution and use of this software in source and binary forms,
Expand Down Expand Up @@ -431,7 +429,7 @@ void Parser::ParseLV1SoftSkinBlock()
std::string bone;
for (unsigned int w = 0; w < numWeights;++w) {
bone.clear();
ParseString(bone,"*MESH_SOFTSKINVERTS.Bone");
ParseString(bone, "*MESH_SOFTSKINVERTS.Bone");

// Find the bone in the mesh's list
std::pair<int,ai_real> me;
Expand Down Expand Up @@ -826,25 +824,23 @@ bool Parser::ParseString(std::string& out,const char* szName)
char szBuffer[1024];
if (!SkipSpaces(&filePtr))
{

ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Unexpected EOL",szName);
LogWarning(szBuffer);
return false;
}
// there must be '"'
if ('\"' != *filePtr)
{

ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Strings are expected "
"to be enclosed in double quotation marks",szName);
LogWarning(szBuffer);
return false;
}
++filePtr;
const char* sz = filePtr;
while (true)
{
if ('\"' == *sz)break;
while (true) {
if ('\"' == *sz)
break;
else if ('\0' == *sz)
{
ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Strings are expected to "
Expand Down
15 changes: 13 additions & 2 deletions code/Assbin/AssbinLoader.cpp
Expand Up @@ -5,8 +5,6 @@ Open Asset Import Library (assimp)

Copyright (c) 2006-2019, assimp team



All rights reserved.

Redistribution and use of this software in source and binary forms,
Expand Down Expand Up @@ -80,6 +78,19 @@ static const aiImporterDesc desc = {
"assbin"
};

// -----------------------------------------------------------------------------------
AssbinImporter::AssbinImporter()
: BaseImporter()
, shortened(false)
, compressed(false) {
// empty
}

// -----------------------------------------------------------------------------------
AssbinImporter::~AssbinImporter() {
// empty
}

// -----------------------------------------------------------------------------------
const aiImporterDesc* AssbinImporter::GetInfo() const {
return &desc;
Expand Down
14 changes: 7 additions & 7 deletions code/Assbin/AssbinLoader.h
Expand Up @@ -5,7 +5,6 @@ Open Asset Import Library (assimp)

Copyright (c) 2006-2019, assimp team


All rights reserved.

Redistribution and use of this software in source and binary forms,
Expand Down Expand Up @@ -67,13 +66,10 @@ namespace Assimp {
// ---------------------------------------------------------------------------------
/** Importer class for 3D Studio r3 and r4 3DS files
*/
class AssbinImporter : public BaseImporter
{
private:
bool shortened;
bool compressed;

class AssbinImporter : public BaseImporter {
public:
AssbinImporter();
~AssbinImporter();
virtual bool CanRead(
const std::string& pFile,
IOSystem* pIOHandler,
Expand All @@ -97,6 +93,10 @@ class AssbinImporter : public BaseImporter
void ReadBinaryTexture(IOStream * stream, aiTexture* tex);
void ReadBinaryLight( IOStream * stream, aiLight* l );
void ReadBinaryCamera( IOStream * stream, aiCamera* cam );

private:
bool shortened;
bool compressed;
};

} // end of namespace Assimp
Expand Down
39 changes: 29 additions & 10 deletions code/B3D/B3DImporter.cpp
Expand Up @@ -5,8 +5,6 @@ Open Asset Import Library (assimp)

Copyright (c) 2006-2019, assimp team



All rights reserved.

Redistribution and use of this software in source and binary forms,
Expand Down Expand Up @@ -45,7 +43,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @brief Implementation of the b3d importer class
*/


#ifndef ASSIMP_BUILD_NO_B3D_IMPORTER

// internal headers
Expand Down Expand Up @@ -94,26 +91,48 @@ void DeleteAllBarePointers(std::vector<T>& x)
}
}

B3DImporter::~B3DImporter()
{
// ------------------------------------------------------------------------------------------------
B3DImporter::B3DImporter()
: BaseImporter()
, _pos(0)
, _buf()
, _stack()
, _textures()
, _materials()
, _vflags(-1)
, _tcsets(-1)
, _tcsize(-1)
, _vertices()
, _nodes()
, _meshes()
, _nodeAnims()
, _animations() {
// empty
}

// ------------------------------------------------------------------------------------------------
bool B3DImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const{
B3DImporter::~B3DImporter() {
// empty
}

// ------------------------------------------------------------------------------------------------
bool B3DImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const{
size_t pos=pFile.find_last_of( '.' );
if( pos==string::npos ) return false;
if (pos == string::npos) {
return false;
}

string ext=pFile.substr( pos+1 );
if( ext.size()!=3 ) return false;
if (ext.size() != 3) {
return false;
}

return (ext[0]=='b' || ext[0]=='B') && (ext[1]=='3') && (ext[2]=='d' || ext[2]=='D');
}

// ------------------------------------------------------------------------------------------------
// Loader meta information
const aiImporterDesc* B3DImporter::GetInfo () const
{
const aiImporterDesc* B3DImporter::GetInfo () const {
return &desc;
}

Expand Down
5 changes: 1 addition & 4 deletions code/B3D/B3DImporter.h
Expand Up @@ -4,7 +4,6 @@ Open Asset Import Library (assimp)

Copyright (c) 2006-2019, assimp team


All rights reserved.

Redistribution and use of this software in source and binary forms,
Expand Down Expand Up @@ -61,7 +60,7 @@ namespace Assimp{

class B3DImporter : public BaseImporter{
public:
B3DImporter() = default;
B3DImporter();
virtual ~B3DImporter();

virtual bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
Expand All @@ -72,7 +71,6 @@ class B3DImporter : public BaseImporter{
virtual void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);

private:

int ReadByte();
int ReadInt();
float ReadFloat();
Expand Down Expand Up @@ -113,7 +111,6 @@ class B3DImporter : public BaseImporter{
void ReadBB3D( aiScene *scene );

unsigned _pos;
// unsigned _size;
std::vector<unsigned char> _buf;
std::vector<unsigned> _stack;

Expand Down
7 changes: 3 additions & 4 deletions code/Collada/ColladaHelper.h
Expand Up @@ -6,7 +6,6 @@ Open Asset Import Library (assimp)

Copyright (c) 2006-2019, assimp team


All rights reserved.

Redistribution and use of this software in source and binary forms,
Expand Down Expand Up @@ -42,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/

#pragma once
#ifndef AI_COLLADAHELPER_H_INC
#define AI_COLLADAHELPER_H_INC

Expand All @@ -58,8 +58,7 @@ namespace Assimp {
namespace Collada {

/** Collada file versions which evolved during the years ... */
enum FormatVersion
{
enum FormatVersion {
FV_1_5_n,
FV_1_4_n,
FV_1_3_n
Expand Down Expand Up @@ -128,7 +127,7 @@ struct Camera
// Name of camera
std::string mName;

// True if it is an orthografic camera
// True if it is an orthographic camera
bool mOrtho;

//! Horizontal field of view in degrees
Expand Down