From f980ec381c5d5d77d765d14921cc62e30c8987c9 Mon Sep 17 00:00:00 2001 From: Thomas Moulard <thomas.moulard@gmail.com> Date: Wed, 29 Dec 2010 00:36:18 +0100 Subject: [PATCH] Fix cppcheck errors. --- src/dgraph/interpreter.cpp | 80 +++++++++++++++++---------------- src/dgraph/plugin-loader.cpp | 12 +++++ src/dgraph/pool.cpp | 26 +++++------ src/shell/functions.cpp | 4 +- src/traces/tracer-real-time.cpp | 11 +++-- 5 files changed, 76 insertions(+), 57 deletions(-) diff --git a/src/dgraph/interpreter.cpp b/src/dgraph/interpreter.cpp index 3728729..5ae153d 100644 --- a/src/dgraph/interpreter.cpp +++ b/src/dgraph/interpreter.cpp @@ -291,37 +291,44 @@ cmdRun( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os } const int SIZE = 16384; - char line[SIZE];int lineIdx; - string name; - try{ - for( lineIdx=1;;lineIdx++ ) - { - dgDEBUGIN(15); - - script.getline(line,SIZE); - if(! script.good() ) break; - - istringstream issTmp(line); - if( issTmp >> name ) + char line[SIZE]; + int lineIdx = 0; + try + { + for (lineIdx = 1;; ++lineIdx) + { + dgDEBUGIN(15); + + script.getline (line, SIZE); + if (!script.good ()) + break; + + std::string name; + istringstream issTmp (line); + if (issTmp >> name) { - issTmp.getline(line,SIZE); - istringstream iss(line); - - dgDEBUG(25) << "Run <"<<name<<"> with args <"<<line<<">"<<endl; - cmd( name,iss,os ); - - dgDEBUGOUT(15); + issTmp.getline (line,SIZE); + std::istringstream iss (line); + + dgDEBUG(25) + << "Run <" << name << "> with args <" << line << ">" + << std::endl; + cmd (name, iss, os); + + dgDEBUGOUT(15); } - } - } catch( ExceptionAbstract& exc ) { - //FIXME: exception should be changed instead. - std::string& msg = const_cast<std::string&>(exc.getStringMessage()); - std::stringstream oss; - oss << " (in line " << lineIdx <<" of file <" << filename << ">)"; - msg = msg + oss.str(); - throw exc; + } } - + catch (ExceptionAbstract& exc) + { + //FIXME: exception should be changed instead. + std::string& msg = const_cast<std::string&>(exc.getStringMessage()); + std::stringstream oss; + oss << " (in line " << lineIdx <<" of file <" << filename << ">)"; + msg = msg + oss.str(); + throw exc; + } + dgDEBUGOUT(15); } @@ -499,19 +506,16 @@ ShellFunctionRegisterer( const std::string& funName, void Interpreter::writeCompletionList(std::ostream& os) { - for( FunctionMap::iterator iter=functionMap.begin(); - iter!=functionMap.end();iter++ ) + for (FunctionMap::iterator iter=functionMap.begin (); + iter != functionMap.end (); ++iter) { const std::string & name = iter->first; os << name << std::endl; } - - - -} - -namespace dynamicgraph { -//! The global g_shell object. - Interpreter g_shell; } +namespace dynamicgraph +{ + //! The global g_shell object. + Interpreter g_shell; +} // end of namespace dynamicgraph diff --git a/src/dgraph/plugin-loader.cpp b/src/dgraph/plugin-loader.cpp index a633859..27869e9 100644 --- a/src/dgraph/plugin-loader.cpp +++ b/src/dgraph/plugin-loader.cpp @@ -145,6 +145,18 @@ loadPlugins( void ) { std::string wrongLib = *iter; pluginNames.erase(iter); + + // FIXME: this line has been added to avoid, since erasing + // an element from a list invalidates the underlying + // iterator. However I am not sure whether loading twice + // the plug-ins is safe or not and should be thoroughly + // tested. + // + // Under Linux this line should have no effect as an + // exception is thrown just after. MS Windows do not raise + // an exception here and must have an incoherent behavior + // anyway... + iter = pluginNames.begin(); #ifndef WIN32 dgDEBUG(5) << "Failure while loading: " <<dlerror() <<endl; DG_THROW ExceptionFactory( ExceptionFactory::DYNAMIC_LOADING, diff --git a/src/dgraph/pool.cpp b/src/dgraph/pool.cpp index 7acc31e..66a311d 100644 --- a/src/dgraph/pool.cpp +++ b/src/dgraph/pool.cpp @@ -108,21 +108,17 @@ void PoolStorage:: clearPlugin( const std::string& name ) { dgDEBUGIN(5); - std::list< Entity* > toDelete; + std::list<Entity*> toDelete; - for( Entities::iterator entPtr=entity.begin(); entPtr!=entity.end(); entPtr++ ) - { - if( entPtr->second->getClassName() == name ) - { toDelete.push_back( entPtr->second ); } - } + for (Entities::iterator entPtr = entity.begin (); + entPtr != entity.end (); ++entPtr) + if (entPtr->second->getClassName() == name) + toDelete.push_back (entPtr->second); - for( std::list< Entity* >::iterator iter=toDelete.begin(); - iter!=toDelete.end(); ++iter ) - { - delete (Entity*) *iter; - } + for (std::list< Entity* >::iterator iter = toDelete.begin (); + iter != toDelete.end (); ++iter) + delete (Entity*) *iter; dgDEBUGOUT(5); - return; } @@ -174,7 +170,7 @@ writeGraph(const std::string &aFileName) GraphFile << "\t} " << std::endl; for( Entities::iterator iter=entity.begin(); - iter!=entity.end();iter++ ) + iter!=entity.end(); ++iter) { Entity* ent = iter->second; GraphFile << ent->getName() @@ -193,7 +189,7 @@ void PoolStorage:: writeCompletionList(std::ostream& os) { for( Entities::iterator iter=entity.begin(); - iter!=entity.end();iter++ ) + iter!=entity.end(); ++iter) { Entity* ent = iter->second; ent->writeCompletionList(os); @@ -221,7 +217,7 @@ commandLine( const std::string& objectName,const std::string& functionName, else if( functionName=="list" ) { for( Entities::iterator iter=entity.begin(); - iter!=entity.end();iter++ ) + iter!=entity.end(); ++iter) { Entity* ent = iter->second; os << ent->getName() diff --git a/src/shell/functions.cpp b/src/shell/functions.cpp index 5900e9c..36f6e90 100644 --- a/src/shell/functions.cpp +++ b/src/shell/functions.cpp @@ -372,11 +372,13 @@ cmdEnableTrace( const std::string cmdLine, istringstream& cmdArg, std::ostream& << "\t\tOpen/close the file <filename> for debug tracing." <<endl; return; } - string opt,filename; cmdArg >> ws; if( cmdArg.good() ) { + std::string opt; + std::string filename; + cmdArg>>opt>>ws; if( opt=="true" ) if( cmdArg.good() ) diff --git a/src/traces/tracer-real-time.cpp b/src/traces/tracer-real-time.cpp index b85ae43..f441057 100644 --- a/src/traces/tracer-real-time.cpp +++ b/src/traces/tracer-real-time.cpp @@ -52,7 +52,7 @@ OutStringStream:: ~OutStringStream( void ) { dgDEBUGIN(15); - if( buffer ) delete [] buffer ; + delete[] buffer; dgDEBUGOUT(15); } @@ -60,9 +60,14 @@ void OutStringStream:: resize( const unsigned int & size ) { dgDEBUGIN(15); - index=0; bufferSize = size; full=false; - if( 0!=buffer ) delete [] buffer; + + index=0; + bufferSize = size; + full=false; + + delete[] buffer; buffer = new char [size]; + dgDEBUGOUT(15); } -- GitLab