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 a60f09a3beb..1844dc7f689 100644 --- a/lib/check64bit.h +++ b/lib/check64bit.h @@ -75,7 +75,7 @@ class CPPCHECKLIB Check64BitPortability : public Check { 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 508f1e743e6..2d252ba7c1b 100644 --- a/lib/checkassignif.h +++ b/lib/checkassignif.h @@ -80,7 +80,7 @@ class CPPCHECKLIB CheckAssignIf : public Check { 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 9f56da7e3c3..dd6958892c4 100644 --- a/lib/checkautovariables.h +++ b/lib/checkautovariables.h @@ -100,7 +100,7 @@ class CPPCHECKLIB CheckAutoVariables : public Check { 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 8908509a555..912120b06f5 100644 --- a/lib/checkboost.h +++ b/lib/checkboost.h @@ -61,7 +61,7 @@ class CPPCHECKLIB CheckBoost : public Check { 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 55861678e45..822e061298d 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -246,7 +246,7 @@ class CPPCHECKLIB CheckBufferOverrun : public Check { } private: - std::string myName() const { + static std::string myName() { return "Bounds checking"; } diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 3ae765d1151..42133459979 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 8d323be4770..7d9f727b28e 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -146,7 +146,7 @@ class CPPCHECKLIB CheckClass : public Check { c.suggestInitializationList(0, "variable"); } - std::string myName() const { + static std::string myName() { return "Class"; } @@ -213,13 +213,13 @@ class CPPCHECKLIB CheckClass : public Check { * @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 @@ class CPPCHECKLIB CheckClass : public Check { */ 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 e0bb3a672f0..cd2ba0eea05 100644 --- a/lib/checkexceptionsafety.h +++ b/lib/checkexceptionsafety.h @@ -107,7 +107,7 @@ class CPPCHECKLIB CheckExceptionSafety : public Check { } /** 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 750b5fcabc8..1f5625557c3 100644 --- a/lib/checkinternal.h +++ b/lib/checkinternal.h @@ -82,7 +82,7 @@ class CPPCHECKLIB CheckInternal : public Check { 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 f44d518b71b..87a96533a0f 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -114,7 +114,7 @@ class CPPCHECKLIB CheckIO : public Check { 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 c872a74fffc..cf4f3954ed1 100644 --- a/lib/checkleakautovar.h +++ b/lib/checkleakautovar.h @@ -123,7 +123,7 @@ class CPPCHECKLIB CheckLeakAutoVar : public Check { 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 cb223deccb7..df88a87cf56 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -325,7 +325,7 @@ class CPPCHECKLIB CheckMemoryLeakInFunction : private Check, public CheckMemoryL * 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 @@ class CPPCHECKLIB CheckMemoryLeakInClass : private Check, private CheckMemoryLea 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 @@ class CPPCHECKLIB CheckMemoryLeakStructMember : private Check, private CheckMemo 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 @@ class CPPCHECKLIB CheckMemoryLeakNoVar : private Check, private CheckMemoryLeak 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 890c72a281a..95389a49a5a 100644 --- a/lib/checknonreentrantfunctions.h +++ b/lib/checknonreentrantfunctions.h @@ -92,7 +92,7 @@ class CPPCHECKLIB CheckNonReentrantFunctions : public Check { } } - std::string myName() const { + static std::string myName() { return "Non reentrant functions"; } diff --git a/lib/checknullpointer.h b/lib/checknullpointer.h index 1d7c3e465cb..5daa575ada8 100644 --- a/lib/checknullpointer.h +++ b/lib/checknullpointer.h @@ -110,7 +110,7 @@ class CPPCHECKLIB CheckNullPointer : public Check { } /** 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 3985a7de002..5520e9ca05d 100644 --- a/lib/checkobsoletefunctions.h +++ b/lib/checkobsoletefunctions.h @@ -131,7 +131,7 @@ class CPPCHECKLIB CheckObsoleteFunctions : public Check { } } - std::string myName() const { + static std::string myName() { return "Obsolete functions"; } diff --git a/lib/checkother.h b/lib/checkother.h index 85001cf67f0..99b69f7a277 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -353,7 +353,7 @@ class CPPCHECKLIB CheckOther : public Check { c.moduloAlwaysTrueFalseError(0, "1"); } - std::string myName() const { + static std::string myName() { return "Other"; } @@ -380,7 +380,6 @@ class CPPCHECKLIB CheckOther : public Check { "* 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 cdb086ec03f..b8e96aa41dc 100644 --- a/lib/checkpostfixoperator.h +++ b/lib/checkpostfixoperator.h @@ -60,7 +60,7 @@ class CPPCHECKLIB CheckPostfixOperator : public Check { 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 a3c2a87715b..b68306a74d2 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -204,7 +204,7 @@ class CPPCHECKLIB CheckStl : public Check { 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 3a522ff3b2e..9d025646b89 100644 --- a/lib/checkuninitvar.h +++ b/lib/checkuninitvar.h @@ -96,7 +96,7 @@ class CPPCHECKLIB CheckUninitVar : public Check { 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 835a01cbb57..f97f1e5748a 100644 --- a/lib/checkunusedfunctions.h +++ b/lib/checkunusedfunctions.h @@ -69,7 +69,7 @@ class CPPCHECKLIB CheckUnusedFunctions: public Check { } - std::string myName() const { + static std::string myName() { return "Unused functions"; } diff --git a/lib/checkunusedvar.h b/lib/checkunusedvar.h index 1d3503cea31..a98e639035b 100644 --- a/lib/checkunusedvar.h +++ b/lib/checkunusedvar.h @@ -90,7 +90,7 @@ class CPPCHECKLIB CheckUnusedVar : public Check { c.unusedStructMemberError(0, "structname", "variable"); } - std::string myName() const { + static std::string myName() { return "UnusedVar"; }