From 1b40668e04711f015c2a021513941ea8aa49d4dd Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 2 Aug 2012 09:50:48 -0700 Subject: [PATCH] Refactorizations: - Made several functions (Check*::myName and others) because they don't touch depend on a specific instance. (cppcheck findings) - Removed description of a check in CheckConst that has moved to CheckIO --- lib/check64bit.h | 2 +- lib/checkassignif.h | 2 +- lib/checkautovariables.h | 2 +- lib/checkboost.h | 2 +- lib/checkbufferoverrun.h | 2 +- lib/checkclass.cpp | 6 +++--- lib/checkclass.h | 8 ++++---- lib/checkexceptionsafety.h | 2 +- lib/checkinternal.h | 2 +- lib/checkio.h | 2 +- lib/checkleakautovar.h | 2 +- lib/checkmemoryleak.h | 8 ++++---- lib/checknonreentrantfunctions.h | 2 +- lib/checknullpointer.h | 2 +- lib/checkobsoletefunctions.h | 2 +- lib/checkother.h | 3 +-- lib/checkpostfixoperator.h | 2 +- lib/checkstl.h | 2 +- lib/checkuninitvar.h | 2 +- lib/checkunusedfunctions.h | 2 +- lib/checkunusedvar.h | 2 +- 21 files changed, 29 insertions(+), 30 deletions(-) diff --git a/lib/check64bit.h b/lib/check64bit.h index a60f09a3b..1844dc7f6 100644 --- a/lib/check64bit.h +++ b/lib/check64bit.h @@ -75,7 +75,7 @@ private: c.returnPointerError(0); } - std::string myName() const { + static std::string myName() { return "64-bit portability"; } diff --git a/lib/checkassignif.h b/lib/checkassignif.h index 508f1e743..2d252ba7c 100644 --- a/lib/checkassignif.h +++ b/lib/checkassignif.h @@ -80,7 +80,7 @@ private: c.multiConditionError(0,1); } - std::string myName() const { + static std::string myName() { return "Match assignments and conditions"; } diff --git a/lib/checkautovariables.h b/lib/checkautovariables.h index 9f56da7e3..dd6958892 100644 --- a/lib/checkautovariables.h +++ b/lib/checkautovariables.h @@ -100,7 +100,7 @@ private: c.errorReturnAddressOfFunctionParameter(0, "parameter"); } - std::string myName() const { + static std::string myName() { return "Auto Variables"; } diff --git a/lib/checkboost.h b/lib/checkboost.h index 8908509a5..912120b06 100644 --- a/lib/checkboost.h +++ b/lib/checkboost.h @@ -61,7 +61,7 @@ private: c.boostForeachError(0); } - std::string myName() const { + static std::string myName() { return "Boost usage"; } diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index 55861678e..822e06129 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -246,7 +246,7 @@ public: } private: - std::string myName() const { + static std::string myName() { return "Bounds checking"; } diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 3ae765d11..421334599 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -153,7 +153,7 @@ void CheckClass::constructors() } } -bool CheckClass::canNotCopy(const Scope *scope) const +bool CheckClass::canNotCopy(const Scope *scope) { std::list::const_iterator func; bool privateAssign = false; @@ -195,13 +195,13 @@ void CheckClass::initVar(const std::string &varname, const Scope *scope, std::ve } } -void CheckClass::assignAllVar(std::vector &usage) const +void CheckClass::assignAllVar(std::vector &usage) { for (std::size_t i = 0; i < usage.size(); ++i) usage[i].assign = true; } -void CheckClass::clearAllVar(std::vector &usage) const +void CheckClass::clearAllVar(std::vector &usage) { for (std::size_t i = 0; i < usage.size(); ++i) { usage[i].assign = false; diff --git a/lib/checkclass.h b/lib/checkclass.h index 8d323be47..7d9f727b2 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -146,7 +146,7 @@ private: c.suggestInitializationList(0, "variable"); } - std::string myName() const { + static std::string myName() { return "Class"; } @@ -213,13 +213,13 @@ private: * @brief set all variables in list assigned * @param usage reference to usage vector */ - void assignAllVar(std::vector &usage) const; + static void assignAllVar(std::vector &usage); /** * @brief set all variables in list not assigned and not initialized * @param usage reference to usage vector */ - void clearAllVar(std::vector &usage) const; + static void clearAllVar(std::vector &usage); /** * @brief parse a scope for a constructor or member function and set the "init" flags in the provided varlist @@ -230,7 +230,7 @@ private: */ void initializeVarList(const Function &func, std::list &callstack, const Scope *scope, std::vector &usage); - bool canNotCopy(const Scope *scope) const; + static bool canNotCopy(const Scope *scope); }; /// @} //--------------------------------------------------------------------------- diff --git a/lib/checkexceptionsafety.h b/lib/checkexceptionsafety.h index e0bb3a672..cd2ba0eea 100644 --- a/lib/checkexceptionsafety.h +++ b/lib/checkexceptionsafety.h @@ -107,7 +107,7 @@ private: } /** Short description of class (for --doc) */ - std::string myName() const { + static std::string myName() { return "Exception Safety"; } diff --git a/lib/checkinternal.h b/lib/checkinternal.h index 750b5fcab..1f5625557 100644 --- a/lib/checkinternal.h +++ b/lib/checkinternal.h @@ -82,7 +82,7 @@ private: c.unknownPatternError(0, "%typ"); } - std::string myName() const { + static std::string myName() { return "cppcheck internal API usage"; } diff --git a/lib/checkio.h b/lib/checkio.h index f44d518b7..87a96533a 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -114,7 +114,7 @@ private: c.invalidScanfFormatWidthError(0, 10, 5, NULL); } - std::string myName() const { + static std::string myName() { return "IO"; } diff --git a/lib/checkleakautovar.h b/lib/checkleakautovar.h index c872a74ff..cf4f3954e 100644 --- a/lib/checkleakautovar.h +++ b/lib/checkleakautovar.h @@ -123,7 +123,7 @@ private: c.configurationInfo(0, "f"); // user configuration is needed to complete analysis } - std::string myName() const { + static std::string myName() { return "Leaks (auto variables)"; } diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index cb223decc..df88a87cf 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -325,7 +325,7 @@ private: * Get name of class (--doc) * @return name of class */ - std::string myName() const { + static std::string myName() { return "Memory leaks (function variables)"; } @@ -382,7 +382,7 @@ private: void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const { } - std::string myName() const { + static std::string myName() { return "Memory leaks (class variables)"; } @@ -421,7 +421,7 @@ private: void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const { } - std::string myName() const { + static std::string myName() { return "Memory leaks (struct members)"; } @@ -460,7 +460,7 @@ private: c.functionCallLeak(0, "funcName", "funcName"); } - std::string myName() const { + static std::string myName() { return "Memory leaks (address not taken)"; } diff --git a/lib/checknonreentrantfunctions.h b/lib/checknonreentrantfunctions.h index 890c72a28..95389a49a 100644 --- a/lib/checknonreentrantfunctions.h +++ b/lib/checknonreentrantfunctions.h @@ -92,7 +92,7 @@ private: } } - std::string myName() const { + static std::string myName() { return "Non reentrant functions"; } diff --git a/lib/checknullpointer.h b/lib/checknullpointer.h index 1d7c3e465..5daa575ad 100644 --- a/lib/checknullpointer.h +++ b/lib/checknullpointer.h @@ -110,7 +110,7 @@ private: } /** Name of check */ - std::string myName() const { + static std::string myName() { return "Null pointer"; } diff --git a/lib/checkobsoletefunctions.h b/lib/checkobsoletefunctions.h index 3985a7de0..5520e9ca0 100644 --- a/lib/checkobsoletefunctions.h +++ b/lib/checkobsoletefunctions.h @@ -131,7 +131,7 @@ private: } } - std::string myName() const { + static std::string myName() { return "Obsolete functions"; } diff --git a/lib/checkother.h b/lib/checkother.h index 85001cf67..99b69f7a2 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -353,7 +353,7 @@ private: c.moduloAlwaysTrueFalseError(0, "1"); } - std::string myName() const { + static std::string myName() { return "Other"; } @@ -380,7 +380,6 @@ private: "* redundant if\n" "* bad usage of the function 'strtol'\n" "* [[CheckUnsignedDivision|unsigned division]]\n" - "* Dangerous usage of 'scanf'\n" "* passing parameter by value\n" "* [[IncompleteStatement|Incomplete statement]]\n" "* [[charvar|check how signed char variables are used]]\n" diff --git a/lib/checkpostfixoperator.h b/lib/checkpostfixoperator.h index cdb086ec0..b8e96aa41 100644 --- a/lib/checkpostfixoperator.h +++ b/lib/checkpostfixoperator.h @@ -60,7 +60,7 @@ private: c.postfixOperatorError(0); } - std::string myName() const { + static std::string myName() { return "Using postfix operators"; } diff --git a/lib/checkstl.h b/lib/checkstl.h index a3c2a8771..b68306a74 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -204,7 +204,7 @@ private: c.uselessCallsEmptyError(0); } - std::string myName() const { + static std::string myName() { return "STL usage"; } diff --git a/lib/checkuninitvar.h b/lib/checkuninitvar.h index 3a522ff3b..9d025646b 100644 --- a/lib/checkuninitvar.h +++ b/lib/checkuninitvar.h @@ -96,7 +96,7 @@ private: c.uninitvarError(0, "varname"); } - std::string myName() const { + static std::string myName() { return "Uninitialized variables"; } diff --git a/lib/checkunusedfunctions.h b/lib/checkunusedfunctions.h index 835a01cbb..f97f1e574 100644 --- a/lib/checkunusedfunctions.h +++ b/lib/checkunusedfunctions.h @@ -69,7 +69,7 @@ private: } - std::string myName() const { + static std::string myName() { return "Unused functions"; } diff --git a/lib/checkunusedvar.h b/lib/checkunusedvar.h index 1d3503cea..a98e63903 100644 --- a/lib/checkunusedvar.h +++ b/lib/checkunusedvar.h @@ -90,7 +90,7 @@ private: c.unusedStructMemberError(0, "structname", "variable"); } - std::string myName() const { + static std::string myName() { return "UnusedVar"; }