CodeQuality improvements

Several small code improvements based on a cppcheck result
pull/581/head
rob100 2015-06-05 09:52:06 +02:00
parent 36a9f2be1a
commit b8c12fdc6f
25 changed files with 49 additions and 44 deletions

View File

@ -757,7 +757,7 @@ void Discreet3DSImporter::GenerateNodeGraph(aiScene* pcOut)
pcNode->mNumMeshes = 1;
// Build a name for the node
pcNode->mName.length = sprintf(pcNode->mName.data,"3DSMesh_%i",i);
pcNode->mName.length = sprintf(pcNode->mName.data,"3DSMesh_%u",i);
}
// Build dummy nodes for all cameras

View File

@ -143,9 +143,9 @@ void Parser::LogWarning(const char* szWarn)
char szTemp[1024];
#if _MSC_VER >= 1400
sprintf_s(szTemp,"Line %i: %s",iLineNumber,szWarn);
sprintf_s(szTemp,"Line %u: %s",iLineNumber,szWarn);
#else
snprintf(szTemp,1024,"Line %i: %s",iLineNumber,szWarn);
snprintf(szTemp,1024,"Line %u: %s",iLineNumber,szWarn);
#endif
// output the warning to the logger ...
@ -159,9 +159,9 @@ void Parser::LogInfo(const char* szWarn)
char szTemp[1024];
#if _MSC_VER >= 1400
sprintf_s(szTemp,"Line %i: %s",iLineNumber,szWarn);
sprintf_s(szTemp,"Line %u: %s",iLineNumber,szWarn);
#else
snprintf(szTemp,1024,"Line %i: %s",iLineNumber,szWarn);
snprintf(szTemp,1024,"Line %u: %s",iLineNumber,szWarn);
#endif
// output the information to the logger ...
@ -175,9 +175,9 @@ AI_WONT_RETURN void Parser::LogError(const char* szWarn)
char szTemp[1024];
#if _MSC_VER >= 1400
sprintf_s(szTemp,"Line %i: %s",iLineNumber,szWarn);
sprintf_s(szTemp,"Line %u: %s",iLineNumber,szWarn);
#else
snprintf(szTemp,1024,"Line %i: %s",iLineNumber,szWarn);
snprintf(szTemp,1024,"Line %u: %s",iLineNumber,szWarn);
#endif
// throw an exception

View File

@ -147,7 +147,7 @@ void DeboneProcess::Execute( aiScene* pScene)
if(!DefaultLogger::isNullLogger()) {
char buffer[1024];
::sprintf(buffer,"Removed %i bones. Input bones: %i. Output bones: %i",in-out,in,out);
::sprintf(buffer,"Removed %u bones. Input bones: %u. Output bones: %u",in-out,in,out);
DefaultLogger::get()->info(buffer);
}

View File

@ -258,7 +258,7 @@ void DefaultLogger::OnDebug( const char* message )
return;
char msg[MAX_LOG_MESSAGE_LENGTH + 16];
::sprintf(msg,"Debug, T%i: %s", GetThreadID(), message );
::sprintf(msg,"Debug, T%u: %s", GetThreadID(), message );
WriteToStreams( msg, Logger::Debugging );
}
@ -268,7 +268,7 @@ void DefaultLogger::OnDebug( const char* message )
void DefaultLogger::OnInfo( const char* message )
{
char msg[MAX_LOG_MESSAGE_LENGTH + 16];
::sprintf(msg,"Info, T%i: %s", GetThreadID(), message );
::sprintf(msg,"Info, T%u: %s", GetThreadID(), message );
WriteToStreams( msg , Logger::Info );
}
@ -278,7 +278,7 @@ void DefaultLogger::OnInfo( const char* message )
void DefaultLogger::OnWarn( const char* message )
{
char msg[MAX_LOG_MESSAGE_LENGTH + 16];
::sprintf(msg,"Warn, T%i: %s", GetThreadID(), message );
::sprintf(msg,"Warn, T%u: %s", GetThreadID(), message );
WriteToStreams( msg, Logger::Warn );
}
@ -288,7 +288,7 @@ void DefaultLogger::OnWarn( const char* message )
void DefaultLogger::OnError( const char* message )
{
char msg[MAX_LOG_MESSAGE_LENGTH + 16];
::sprintf(msg,"Error, T%i: %s", GetThreadID(), message );
::sprintf(msg,"Error, T%u: %s", GetThreadID(), message );
WriteToStreams( msg, Logger::Err );
}

View File

@ -194,7 +194,7 @@ void IRRImporter::BuildSkybox(std::vector<aiMesh*>& meshes, std::vector<aiMateri
aiMaterial* out = ( aiMaterial* ) (*(materials.end()-(6-i)));
aiString s;
s.length = ::sprintf( s.data, "SkyboxSide_%i",i );
s.length = ::sprintf( s.data, "SkyboxSide_%u",i );
out->AddProperty(&s,AI_MATKEY_NAME);
int shading = aiShadingMode_NoShading;

View File

@ -209,7 +209,7 @@ void LWOImporter::InternReadFile( const std::string& pFile,
// we need to check now whether the requested layer has been found.
if (UINT_MAX != configLayerIndex) {
unsigned int layerCount = 0;
for(std::list<LWO::Layer>::iterator itLayers=mLayers->begin(); itLayers!=mLayers->end(); itLayers++)
for(std::list<LWO::Layer>::iterator itLayers=mLayers->begin(); itLayers!=mLayers->end(); ++itLayers)
if (!itLayers->skip)
layerCount++;
if (layerCount!=2)

View File

@ -450,7 +450,7 @@ void LWSImporter::BuildGraph(aiNode* nd, LWS::NodeDesc& src, std::vector<Attachm
}
// Add children
if (src.children.size()) {
if (!src.children.empty()) {
nd->mChildren = new aiNode*[src.children.size()];
for (std::list<LWS::NodeDesc*>::iterator it = src.children.begin(); it != src.children.end(); ++it) {
aiNode* ndd = nd->mChildren[nd->mNumChildren++] = new aiNode();

View File

@ -193,7 +193,7 @@ void LimitBoneWeightsProcess::ProcessMesh( aiMesh* pMesh)
if (!DefaultLogger::isNullLogger()) {
char buffer[1024];
::sprintf(buffer,"Removed %i weights. Input bones: %i. Output bones: %i",removed,old_bones,pMesh->mNumBones);
::sprintf(buffer,"Removed %u weights. Input bones: %u. Output bones: %u",removed,old_bones,pMesh->mNumBones);
DefaultLogger::get()->info(buffer);
}
}

View File

@ -791,7 +791,7 @@ void MD3Importer::InternReadFile( const std::string& pFile,
// Adjust all texture paths in the shader
const char* header_name = pcHeader->NAME;
if (shaders.blocks.size()) {
if (!shaders.blocks.empty()) {
for (std::list< Q3Shader::ShaderDataBlock >::iterator dit = shaders.blocks.begin(); dit != shaders.blocks.end(); ++dit) {
ConvertPath((*dit).name.c_str(),header_name,(*dit).name);
@ -881,7 +881,7 @@ void MD3Importer::InternReadFile( const std::string& pFile,
// Now search the current shader for a record with this name (
// excluding texture file extension)
if (shaders.blocks.size()) {
if (!shaders.blocks.empty()) {
std::string::size_type s = convertedPath.find_last_of('.');
if (s == std::string::npos)

View File

@ -95,7 +95,7 @@ MD5Parser::MD5Parser(char* _buffer, unsigned int _fileSize )
/*static*/ AI_WONT_RETURN void MD5Parser::ReportError (const char* error, unsigned int line)
{
char szBuffer[1024];
::sprintf(szBuffer,"[MD5] Line %i: %s",line,error);
::sprintf(szBuffer,"[MD5] Line %u: %s",line,error);
throw DeadlyImportError(szBuffer);
}
@ -104,7 +104,7 @@ MD5Parser::MD5Parser(char* _buffer, unsigned int _fileSize )
/*static*/ void MD5Parser::ReportWarning (const char* warn, unsigned int line)
{
char szBuffer[1024];
::sprintf(szBuffer,"[MD5] Line %i: %s",line,warn);
::sprintf(szBuffer,"[MD5] Line %u: %s",line,warn);
DefaultLogger::get()->warn(szBuffer);
}

View File

@ -264,7 +264,7 @@ void MDLImporter::SizeCheck(const void* szPos, const char* szFile, unsigned int
char szBuffer[1024];
::sprintf(szBuffer,"Invalid MDL file. The file is too small "
"or contains invalid data (File: %s Line: %i)",szFilePtr,iLine);
"or contains invalid data (File: %s Line: %u)",szFilePtr,iLine);
throw DeadlyImportError(szBuffer);
}
@ -1536,7 +1536,7 @@ void MDLImporter::InternReadFile_3DGS_MDL7( )
// setup the name of the node
char* const szBuffer = &aszGroupNameBuffer[i*AI_MDL7_MAX_GROUPNAMESIZE];
if ('\0' == *szBuffer)
pcNode->mName.length = ::sprintf(szBuffer,"Group_%i",p);
pcNode->mName.length = ::sprintf(szBuffer,"Group_%u",p);
else pcNode->mName.length = ::strlen(szBuffer);
::strcpy(pcNode->mName.data,szBuffer);
++p;

View File

@ -531,7 +531,7 @@ void MS3DImporter::InternReadFile( const std::string& pFile,
}
// allocate storage for bones
if(mybones.size()) {
if(!mybones.empty()) {
std::vector<unsigned int> bmap(joints.size());
m->mBones = new aiBone*[mybones.size()]();
for(BoneSet::const_iterator it = mybones.begin(); it != mybones.end(); ++it) {

View File

@ -1115,7 +1115,7 @@ void NFFImporter::InternReadFile( const std::string& pFile,
aiNode* nd = *ppcChildren = new aiNode();
nd->mParent = root;
nd->mName.length = ::sprintf(nd->mName.data,"<NFF_Light%i>",i);
nd->mName.length = ::sprintf(nd->mName.data,"<NFF_Light%u>",i);
// allocate the light in the scene data structure
aiLight* out = pScene->mLights[i] = new aiLight();

View File

@ -288,7 +288,7 @@ int ObjExporter::vecIndexMap::getIndex(const aiVector3D& vec)
void ObjExporter::vecIndexMap::getVectors( std::vector<aiVector3D>& vecs )
{
vecs.resize(vecMap.size());
for(vecIndexMap::dataType::iterator it = vecMap.begin(); it != vecMap.end(); it++){
for(vecIndexMap::dataType::iterator it = vecMap.begin(); it != vecMap.end(); ++it){
vecs[it->second-1] = it->first;
}
}

View File

@ -122,6 +122,11 @@ private:
void reportErrorTokenInFace();
private:
// Copy and assignment constructor should be private
// because the class contains pointer to allocated memory
ObjFileParser(const ObjFileParser& rhs);
ObjFileParser& operator=(const ObjFileParser& rhs);
/// Default material name
static const std::string DEFAULT_MATERIAL;
//! Iterator to current position in buffer

View File

@ -81,7 +81,7 @@ private:
void AssignMaterials(aiScene *pScene, std::vector<aiMaterial*> &materials);
/// Reads material
aiMaterial* ReadMaterial(const std::string &pFile, Assimp::IOSystem *pIOHandler, const std::string MaterialName);
aiMaterial* ReadMaterial(const std::string &pFile, Assimp::IOSystem *pIOHandler, const std::string &MaterialName);
// These functions parse blocks from a material file from @c ss. Starting parsing from "{" and ending it to "}".
bool ReadTechnique(const std::string &techniqueName, std::stringstream &ss, aiMaterial *material);

View File

@ -120,7 +120,7 @@ void OgreImporter::AssignMaterials(aiScene *pScene, std::vector<aiMaterial*> &ma
}
}
aiMaterial* OgreImporter::ReadMaterial(const std::string &pFile, Assimp::IOSystem *pIOHandler, const std::string materialName)
aiMaterial* OgreImporter::ReadMaterial(const std::string &pFile, Assimp::IOSystem *pIOHandler, const std::string &materialName)
{
if (materialName.empty()) {
return 0;

View File

@ -300,7 +300,7 @@ void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
}
DDLNode::DllNodeList childs = node->getChildNodeList();
for( DDLNode::DllNodeList::iterator it = childs.begin(); it != childs.end(); it++ ) {
for( DDLNode::DllNodeList::iterator it = childs.begin(); it != childs.end(); ++it ) {
Grammar::TokenType tokenType( Grammar::matchTokenType( ( *it )->getType().c_str() ) );
switch( tokenType ) {
case Grammar::MetricToken:

View File

@ -225,7 +225,7 @@ void OptimizeGraphProcess::CollectNewChildren(aiNode* nd, std::list<aiNode*>& no
delete[] nd->mChildren;
if (child_nodes.size())
if (!child_nodes.empty())
nd->mChildren = new aiNode*[child_nodes.size()];
else nd->mChildren = NULL;
}
@ -335,7 +335,7 @@ void OptimizeGraphProcess::Execute( aiScene* pScene)
if ( nodes_in != nodes_out) {
char buf[512];
sprintf(buf,"OptimizeGraphProcess finished; Input nodes: %i, Output nodes: %i",nodes_in,nodes_out);
sprintf(buf,"OptimizeGraphProcess finished; Input nodes: %u, Output nodes: %u",nodes_in,nodes_out);
DefaultLogger::get()->info(buf);
}
else DefaultLogger::get()->debug("OptimizeGraphProcess finished");

View File

@ -150,7 +150,7 @@ void OptimizeMeshesProcess::Execute( aiScene* pScene)
if (output.size() != num_old) {
char tmp[512];
::sprintf(tmp,"OptimizeMeshesProcess finished. Input meshes: %i, Output meshes: %i",num_old,pScene->mNumMeshes);
::sprintf(tmp,"OptimizeMeshesProcess finished. Input meshes: %u, Output meshes: %u",num_old,pScene->mNumMeshes);
DefaultLogger::get()->info(tmp);
} else {
DefaultLogger::get()->debug( "OptimizeMeshesProcess finished" );

View File

@ -644,7 +644,7 @@ void PretransformVertices::Execute( aiScene* pScene)
{
aiNode* pcNode = *nodes = new aiNode();
pcNode->mParent = pScene->mRootNode;
pcNode->mName.length = ::sprintf(pcNode->mName.data,"mesh_%i",i);
pcNode->mName.length = ::sprintf(pcNode->mName.data,"mesh_%u",i);
// setup mesh indices
pcNode->mNumMeshes = 1;
@ -656,7 +656,7 @@ void PretransformVertices::Execute( aiScene* pScene)
{
aiNode* pcNode = *nodes = new aiNode();
pcNode->mParent = pScene->mRootNode;
pcNode->mName.length = ::sprintf(pcNode->mName.data,"light_%i",i);
pcNode->mName.length = ::sprintf(pcNode->mName.data,"light_%u",i);
pScene->mLights[i]->mName = pcNode->mName;
}
// generate camera nodes
@ -664,7 +664,7 @@ void PretransformVertices::Execute( aiScene* pScene)
{
aiNode* pcNode = *nodes = new aiNode();
pcNode->mParent = pScene->mRootNode;
pcNode->mName.length = ::sprintf(pcNode->mName.data,"cam_%i",i);
pcNode->mName.length = ::sprintf(pcNode->mName.data,"cam_%u",i);
pScene->mCameras[i]->mName = pcNode->mName;
}
}
@ -707,15 +707,15 @@ void PretransformVertices::Execute( aiScene* pScene)
DefaultLogger::get()->debug("PretransformVerticesProcess finished");
sprintf(buffer,"Removed %i nodes and %i animation channels (%i output nodes)",
sprintf(buffer,"Removed %u nodes and %u animation channels (%u output nodes)",
iOldNodes,iOldAnimationChannels,CountNodes(pScene->mRootNode));
DefaultLogger::get()->info(buffer);
sprintf(buffer,"Kept %i lights and %i cameras",
sprintf(buffer,"Kept %u lights and %u cameras",
pScene->mNumLights,pScene->mNumCameras);
DefaultLogger::get()->info(buffer);
sprintf(buffer,"Moved %i meshes to WCS (number of output meshes: %i)",
sprintf(buffer,"Moved %u meshes to WCS (number of output meshes: %u)",
iOldMeshes,pScene->mNumMeshes);
DefaultLogger::get()->info(buffer);
}

View File

@ -180,7 +180,7 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene)
if (ppcMaterials[idx])
{
aiString sz;
sz.length = ::sprintf(sz.data,"JoinedMaterial_#%i",p);
sz.length = ::sprintf(sz.data,"JoinedMaterial_#%u",p);
((aiMaterial*)ppcMaterials[idx])->AddProperty(&sz,AI_MATKEY_NAME);
}
else
@ -207,7 +207,7 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene)
else
{
char szBuffer[128]; // should be sufficiently large
::sprintf(szBuffer,"RemoveRedundantMatsProcess finished. Removed %i redundant and %i unused materials.",
::sprintf(szBuffer,"RemoveRedundantMatsProcess finished. Removed %u redundant and %u unused materials.",
redundantRemoved,unreferencedRemoved);
DefaultLogger::get()->info(szBuffer);
}

View File

@ -208,7 +208,7 @@ void SMDImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
void SMDImporter::LogErrorNoThrow(const char* msg)
{
char szTemp[1024];
sprintf(szTemp,"Line %i: %s",iLineNumber,msg);
sprintf(szTemp,"Line %u: %s",iLineNumber,msg);
DefaultLogger::get()->error(szTemp);
}
@ -218,7 +218,7 @@ void SMDImporter::LogWarning(const char* msg)
{
char szTemp[1024];
ai_assert(strlen(msg) < 1000);
sprintf(szTemp,"Line %i: %s",iLineNumber,msg);
sprintf(szTemp,"Line %u: %s",iLineNumber,msg);
DefaultLogger::get()->warn(szTemp);
}
@ -647,7 +647,7 @@ void SMDImporter::CreateOutputMaterials()
pScene->mMaterials[iMat] = pcMat;
aiString szName;
szName.length = (size_t)::sprintf(szName.data,"Texture_%i",iMat);
szName.length = (size_t)::sprintf(szName.data,"Texture_%u",iMat);
pcMat->AddProperty(&szName,AI_MATKEY_NAME);
if (aszTextures[iMat].length())

View File

@ -251,7 +251,7 @@ void StepExporter::WriteFile()
mOutput << "))" << endstr;
// write all the unique transformed CARTESIAN and VERTEX
for (MeshesByNodeMap::const_iterator it2 = meshes.begin(); it2 != meshes.end(); it2++)
for (MeshesByNodeMap::const_iterator it2 = meshes.begin(); it2 != meshes.end(); ++it2)
{
const aiNode& node = *(*it2).first;
unsigned int mesh_idx = (*it2).second;

View File

@ -377,7 +377,7 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
aiColor3D color(1.f,1.f,1.f);
aiString s;
::sprintf(s.data,"mat%i_tx%i_",i,materials[i].tex);
::sprintf(s.data,"mat%u_tx%u_",i,materials[i].tex);
// set the two-sided flag
if (materials[i].type == Unreal::MF_NORMAL_TS) {