diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 2ab79b846..64c522a28 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -33,14 +33,12 @@ #include "pathmatch.h" CppCheckExecutor::CppCheckExecutor() + : time1(0), errorlist(false) { - time1 = 0; - errorlist = false; } CppCheckExecutor::~CppCheckExecutor() { - } bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[]) diff --git a/lib/check.h b/lib/check.h index 5e7ddfcdd..d3e283cf5 100644 --- a/lib/check.h +++ b/lib/check.h @@ -42,7 +42,7 @@ public: /** This constructor is used when running checks. */ Check(const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : _name(aname), _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger) + : _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger), _name(aname) { } virtual ~Check() { @@ -85,7 +85,7 @@ public: virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0; /** get error messages */ - virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) = 0; + virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const = 0; /** class name, used to generate documentation */ const std::string& name() const { @@ -109,7 +109,6 @@ public: } protected: - const std::string _name; const Tokenizer * const _tokenizer; const Settings * const _settings; ErrorLogger * const _errorLogger; @@ -123,7 +122,7 @@ protected: } /** report an error */ - void reportError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, std::string msg) { + void reportError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, const std::string& msg) { reportError(callstack, severity, id, msg, false); } @@ -136,17 +135,19 @@ protected: } /** report an inconclusive error */ - void reportInconclusiveError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, std::string msg) { + void reportInconclusiveError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, const std::string& msg) { reportError(callstack, severity, id, msg, true); } private: + const std::string _name; + /** disabled assignment operator */ void operator=(const Check &); /** report an error */ - void reportError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, std::string msg, bool inconclusive) { + void reportError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, const std::string& msg, bool inconclusive) { std::list locationList; for (std::list::const_iterator it = callstack.begin(); it != callstack.end(); ++it) { // --errorlist can provide null values here @@ -180,7 +181,7 @@ namespace std { } inline Check::Check(const std::string &aname) - : _name(aname), _tokenizer(0), _settings(0), _errorLogger(0) + : _tokenizer(0), _settings(0), _errorLogger(0), _name(aname) { instances().push_back(this); instances().sort(std::less()); diff --git a/lib/check64bit.h b/lib/check64bit.h index 7ce52076c..e72fcb434 100644 --- a/lib/check64bit.h +++ b/lib/check64bit.h @@ -64,7 +64,7 @@ private: void assignmentAddressToIntegerError(const Token *tok); void assignmentIntegerToAddressError(const Token *tok); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { Check64BitPortability c(0, settings, errorLogger); c.assignmentAddressToIntegerError(0); c.assignmentIntegerToAddressError(0); diff --git a/lib/checkassignif.h b/lib/checkassignif.h index c2e9931d7..d4fdce5aa 100644 --- a/lib/checkassignif.h +++ b/lib/checkassignif.h @@ -72,7 +72,7 @@ private: void multiConditionError(const Token *tok, unsigned int line1); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckAssignIf c(0, settings, errorLogger); c.assignIfError(0, false); c.comparisonError(0, 6, "==", 1, false); diff --git a/lib/checkautovariables.h b/lib/checkautovariables.h index 6cbcd514a..8eb31ce73 100644 --- a/lib/checkautovariables.h +++ b/lib/checkautovariables.h @@ -87,7 +87,7 @@ private: void errorInvalidDeallocation(const Token *tok); void errorReturnAddressOfFunctionParameter(const Token *tok, const std::string &varname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckAutoVariables c(0,settings,errorLogger); c.errorAutoVariableAssignment(0, false); c.errorReturnAddressToAutoVariable(0); diff --git a/lib/checkboost.h b/lib/checkboost.h index dc28613bf..e7995f253 100644 --- a/lib/checkboost.h +++ b/lib/checkboost.h @@ -55,7 +55,7 @@ public: private: void boostForeachError(const Token *tok); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckBoost c(0, settings, errorLogger); c.boostForeachError(0); } diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index f90a6ed96..ef3ffbc24 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -231,7 +231,7 @@ public: void possibleBufferOverrunError(const Token *tok, const std::string &src, const std::string &dst, bool cat); void possibleReadlinkBufferOverrunError(const Token *tok, const std::string &funcname, const std::string &varname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckBufferOverrun c(0, settings, errorLogger); std::vector indexes; indexes.push_back(2); diff --git a/lib/checkclass.h b/lib/checkclass.h index c179cf5c7..f6418ab17 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -123,7 +123,7 @@ private: void checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname); void initializerListError(const Token *tok1,const Token *tok2, const std::string & classname, const std::string &varname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckClass c(0, settings, errorLogger); c.noConstructorError(0, "classname", false); c.uninitVarError(0, "classname", "varname"); diff --git a/lib/checkexceptionsafety.h b/lib/checkexceptionsafety.h index 5ff70cb43..fc8661f63 100644 --- a/lib/checkexceptionsafety.h +++ b/lib/checkexceptionsafety.h @@ -96,7 +96,7 @@ private: } /** Generate all possible errors (for --errorlist) */ - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckExceptionSafety c(0, settings, errorLogger); c.destructorsError(0); c.deallocThrowError(0, "p"); diff --git a/lib/checkinternal.h b/lib/checkinternal.h index c2483cbbc..037f6dabb 100644 --- a/lib/checkinternal.h +++ b/lib/checkinternal.h @@ -68,7 +68,7 @@ private: void complexPatternError(const Token *tok, const std::string &pattern, const std::string &funcname); void missingPercentCharacterError(const Token *tok, const std::string &pattern, const std::string &funcname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckInternal c(0, settings, errorLogger); c.simplePatternError(0, "class {", "Match"); c.complexPatternError(0, "%type% ( )", "Match"); diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index 8c5fea8ea..4ad6977f7 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -306,7 +306,7 @@ public: void checkScope(const Token *Tok1, const std::string &varname, unsigned int varid, bool classmember, unsigned int sz); /** Report all possible errors (for the --errorlist) */ - void getErrorMessages(ErrorLogger *e, const Settings *settings) { + void getErrorMessages(ErrorLogger *e, const Settings *settings) const { CheckMemoryLeakInFunction c(0, settings, e); c.memleakError(0, "varname"); @@ -381,7 +381,7 @@ private: void checkPublicFunctions(const Scope *scope, const Token *classtok); void publicAllocationError(const Token *tok, const std::string &varname); - void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) + void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const { } std::string myName() const { @@ -420,7 +420,7 @@ private: void checkStructVariable(const Token * const vartok); - void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) + void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const { } std::string myName() const { @@ -456,7 +456,7 @@ private: void functionCallLeak(const Token *loc, const std::string &alloc, const std::string &functionCall); - void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) + void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const { } std::string myName() const { diff --git a/lib/checknonreentrantfunctions.h b/lib/checknonreentrantfunctions.h index fb1fdc437..0ae0714e5 100644 --- a/lib/checknonreentrantfunctions.h +++ b/lib/checknonreentrantfunctions.h @@ -82,7 +82,7 @@ private: } } - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckNonReentrantFunctions c(0, settings, errorLogger); std::map::const_iterator it(_nonReentrantFunctions.begin()), itend(_nonReentrantFunctions.end()); diff --git a/lib/checknullpointer.h b/lib/checknullpointer.h index 72e2f3051..9e311fbc8 100644 --- a/lib/checknullpointer.h +++ b/lib/checknullpointer.h @@ -103,7 +103,7 @@ public: void nullPointerError(const Token *tok, const std::string &varname, const unsigned int line, bool inconclusive = false); /** Get error messages. Used by --errorlist */ - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckNullPointer c(0, settings, errorLogger); c.nullPointerError(0, "pointer"); } diff --git a/lib/checkobsoletefunctions.h b/lib/checkobsoletefunctions.h index fb1242bee..2a6271626 100644 --- a/lib/checkobsoletefunctions.h +++ b/lib/checkobsoletefunctions.h @@ -127,7 +127,7 @@ private: } - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckObsoleteFunctions c(0, settings, errorLogger); std::map::const_iterator it(_obsoletePosixFunctions.begin()), itend(_obsoletePosixFunctions.end()); diff --git a/lib/checkother.h b/lib/checkother.h index 2cbee94f7..f09e7d5bb 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -309,7 +309,7 @@ public: void doubleFreeError(const Token *tok, const std::string &varname); void doubleCloseDirError(const Token *tok, const std::string &varname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckOther c(0, settings, errorLogger); // error diff --git a/lib/checkpostfixoperator.h b/lib/checkpostfixoperator.h index 972c31b25..c71e3ae3a 100644 --- a/lib/checkpostfixoperator.h +++ b/lib/checkpostfixoperator.h @@ -54,7 +54,7 @@ private: /** Report Error */ void postfixOperatorError(const Token *tok); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckPostfixOperator c(0, settings, errorLogger); c.postfixOperatorError(0); } diff --git a/lib/checkstl.h b/lib/checkstl.h index 9c59f5e9f..6df3641e2 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -172,7 +172,7 @@ private: void uselessCallsSwapError(const Token *tok, const std::string &varname); void uselessCallsSubstrError(const Token *tok, const std::string &varname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckStl c(0, settings, errorLogger); c.invalidIteratorError(0, "iterator"); c.iteratorsError(0, "container1", "container2"); diff --git a/lib/checkuninitvar.h b/lib/checkuninitvar.h index ce96ad222..06027735a 100644 --- a/lib/checkuninitvar.h +++ b/lib/checkuninitvar.h @@ -82,7 +82,7 @@ public: void uninitdataError(const Token *tok, const std::string &varname); void uninitvarError(const Token *tok, const std::string &varname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckUninitVar c(0, settings, errorLogger); // error diff --git a/lib/checkunusedfunctions.h b/lib/checkunusedfunctions.h index 37899484e..a8c9a441d 100644 --- a/lib/checkunusedfunctions.h +++ b/lib/checkunusedfunctions.h @@ -49,7 +49,7 @@ public: private: - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckUnusedFunctions c(0, settings, errorLogger); c.unusedFunctionError(errorLogger, "", 0, "funcName"); } diff --git a/lib/checkunusedvar.h b/lib/checkunusedvar.h index 4e891caa7..833713590 100644 --- a/lib/checkunusedvar.h +++ b/lib/checkunusedvar.h @@ -77,7 +77,7 @@ public: void unreadVariableError(const Token *tok, const std::string &varname); void unassignedVariableError(const Token *tok, const std::string &varname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckUnusedVar c(0, settings, errorLogger); // style/warning diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 821dbc937..9ea3496f2 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -36,7 +36,7 @@ * errors or places that could be improved. * Usage: See check() for more info. */ -class CppCheck : public ErrorLogger { +class CppCheck : ErrorLogger { public: /** * @brief Constructor. @@ -134,7 +134,7 @@ public: /** * @brief Get dependencies. Use this after calling 'check'. */ - std::set dependencies() const { + const std::set& dependencies() const { return _dependencies; } @@ -190,7 +190,7 @@ private: ErrorLogger &_errorLogger; /** @brief Current preprocessor configuration */ - std::string cfg; + std::string cfg; }; /// @} diff --git a/lib/timer.cpp b/lib/timer.cpp index b26815d4f..2e928a2db 100644 --- a/lib/timer.cpp +++ b/lib/timer.cpp @@ -31,7 +31,7 @@ */ -void TimerResults::ShowResults() +void TimerResults::ShowResults() const { std::clock_t overallClocks = 0; diff --git a/lib/timer.h b/lib/timer.h index 5647eb825..fcee0d74d 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -52,7 +52,7 @@ public: TimerResults() { } - void ShowResults(); + void ShowResults() const; virtual void AddResults(const std::string& str, std::clock_t clocks); private: diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c9589481d..3fe1938ac 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8280,7 +8280,7 @@ void Tokenizer::simplifyConst() } } -void Tokenizer::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) +void Tokenizer::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { Tokenizer t(settings, errorLogger); t.syntaxError(0, ' '); diff --git a/lib/tokenize.h b/lib/tokenize.h index 83c39b52b..c2a7121cd 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -204,7 +204,7 @@ public: /** * get error messages that the tokenizer generate */ - virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings); + virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const; /** Simplify assignment in function call "f(x=g());" => "x=g();f(x);" */