cleaned up access of the check classes (#5387)

This commit is contained in:
Oliver Stöneberg 2023-09-11 11:12:42 +02:00 committed by GitHub
parent 64cd09ab62
commit bbe45ff0eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 145 additions and 84 deletions

View File

@ -61,10 +61,12 @@ public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
explicit Check(const std::string &aname); explicit Check(const std::string &aname);
protected:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
Check(std::string aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) Check(std::string aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger), mName(std::move(aname)) {} : mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger), mName(std::move(aname)) {}
public:
virtual ~Check() { virtual ~Check() {
if (!mTokenizer) if (!mTokenizer)
instances().remove(this); instances().remove(this);
@ -127,9 +129,9 @@ public:
return false; return false;
} }
protected:
static std::string getMessageId(const ValueFlow::Value &value, const char id[]); static std::string getMessageId(const ValueFlow::Value &value, const char id[]);
protected:
const Tokenizer* const mTokenizer{}; const Tokenizer* const mTokenizer{};
const Settings* const mSettings{}; const Settings* const mSettings{};
ErrorLogger* const mErrorLogger{}; ErrorLogger* const mErrorLogger{};

View File

@ -41,10 +41,13 @@ class Token;
*/ */
class CPPCHECKLIB Check64BitPortability : public Check { class CPPCHECKLIB Check64BitPortability : public Check {
friend class Test64BitPortability;
public: public:
/** This constructor is used when registering the Check64BitPortability */ /** This constructor is used when registering the Check64BitPortability */
Check64BitPortability() : Check(myName()) {} Check64BitPortability() : Check(myName()) {}
private:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
Check64BitPortability(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) Check64BitPortability(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -58,8 +61,6 @@ public:
/** Check for pointer assignment */ /** Check for pointer assignment */
void pointerassignment(); void pointerassignment();
private:
void assignmentAddressToIntegerError(const Token *tok); void assignmentAddressToIntegerError(const Token *tok);
void assignmentIntegerToAddressError(const Token *tok); void assignmentIntegerToAddressError(const Token *tok);
void returnIntegerError(const Token *tok); void returnIntegerError(const Token *tok);

View File

@ -41,9 +41,12 @@ class Token;
*/ */
class CPPCHECKLIB CheckAssert : public Check { class CPPCHECKLIB CheckAssert : public Check {
friend class TestFixture;
public: public:
CheckAssert() : Check(myName()) {} CheckAssert() : Check(myName()) {}
private:
CheckAssert(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckAssert(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -55,11 +58,9 @@ public:
void assertWithSideEffects(); void assertWithSideEffects();
protected:
void checkVariableAssignment(const Token* assignTok, const Scope *assertionScope); void checkVariableAssignment(const Token* assignTok, const Scope *assertionScope);
static bool inSameScope(const Token* returnTok, const Token* assignTok); static bool inSameScope(const Token* returnTok, const Token* assignTok);
private:
void sideEffectInAssertError(const Token *tok, const std::string& functionName); void sideEffectInAssertError(const Token *tok, const std::string& functionName);
void assignmentInAssertError(const Token *tok, const std::string &varname); void assignmentInAssertError(const Token *tok, const std::string &varname);

View File

@ -45,10 +45,13 @@ namespace ValueFlow {
class CPPCHECKLIB CheckAutoVariables : public Check { class CPPCHECKLIB CheckAutoVariables : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckAutoVariables() : Check(myName()) {} CheckAutoVariables() : Check(myName()) {}
private:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckAutoVariables(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckAutoVariables(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -76,7 +79,6 @@ public:
void checkVarLifetimeScope(const Token * start, const Token * end); void checkVarLifetimeScope(const Token * start, const Token * end);
private:
void errorAutoVariableAssignment(const Token *tok, bool inconclusive); void errorAutoVariableAssignment(const Token *tok, bool inconclusive);
void errorReturnDanglingLifetime(const Token *tok, const ValueFlow::Value* val); void errorReturnDanglingLifetime(const Token *tok, const ValueFlow::Value* val);
void errorInvalidLifetime(const Token *tok, const ValueFlow::Value* val); void errorInvalidLifetime(const Token *tok, const ValueFlow::Value* val);

View File

@ -39,10 +39,13 @@ class Token;
/** @brief checks dealing with suspicious usage of boolean type (not for evaluating conditions) */ /** @brief checks dealing with suspicious usage of boolean type (not for evaluating conditions) */
class CPPCHECKLIB CheckBool : public Check { class CPPCHECKLIB CheckBool : public Check {
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckBool() : Check(myName()) {} CheckBool() : Check(myName()) {}
private:
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckBool(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckBool(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -95,7 +98,6 @@ public:
/** @brief %Check if a function returning bool returns an integer other than 0 or 1 */ /** @brief %Check if a function returning bool returns an integer other than 0 or 1 */
void returnValueOfFunctionReturningBool(); void returnValueOfFunctionReturningBool();
private:
// Error messages.. // Error messages..
void comparisonOfFuncReturningBoolError(const Token *tok, const std::string &expression); void comparisonOfFuncReturningBoolError(const Token *tok, const std::string &expression);
void comparisonOfTwoFuncsReturningBoolError(const Token *tok, const std::string &expression1, const std::string &expression2); void comparisonOfTwoFuncsReturningBoolError(const Token *tok, const std::string &expression1, const std::string &expression2);

View File

@ -38,10 +38,13 @@ class Token;
/** @brief %Check Boost usage */ /** @brief %Check Boost usage */
class CPPCHECKLIB CheckBoost : public Check { class CPPCHECKLIB CheckBoost : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckBoost() : Check(myName()) {} CheckBoost() : Check(myName()) {}
private:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckBoost(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckBoost(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -58,7 +61,6 @@ public:
/** @brief %Check for container modification while using the BOOST_FOREACH macro */ /** @brief %Check for container modification while using the BOOST_FOREACH macro */
void checkBoostForeachModification(); void checkBoostForeachModification();
private:
void boostForeachError(const Token *tok); void boostForeachError(const Token *tok);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {

View File

@ -57,11 +57,14 @@ class Token;
* other function and pass a buffer and reads or writes too much data. * other function and pass a buffer and reads or writes too much data.
*/ */
class CPPCHECKLIB CheckBufferOverrun : public Check { class CPPCHECKLIB CheckBufferOverrun : public Check {
public: friend class TestBufferOverrun;
friend class TestFixture;
public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckBufferOverrun() : Check(myName()) {} CheckBufferOverrun() : Check(myName()) {}
private:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -97,8 +100,6 @@ public:
/** @brief Analyse all file infos for all TU */ /** @brief Analyse all file infos for all TU */
bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override; bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override;
private:
void arrayIndex(); void arrayIndex();
void arrayIndexError(const Token* tok, void arrayIndexError(const Token* tok,
const std::vector<Dimension>& dimensions, const std::vector<Dimension>& dimensions,

View File

@ -51,10 +51,18 @@ namespace tinyxml2 {
/** @brief %Check classes. Uninitialized member variables, non-conforming operators, missing virtual destructor, etc */ /** @brief %Check classes. Uninitialized member variables, non-conforming operators, missing virtual destructor, etc */
class CPPCHECKLIB CheckClass : public Check { class CPPCHECKLIB CheckClass : public Check {
friend class TestClass;
friend class TestConstructors;
friend class TestUnusedPrivateFunction;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckClass() : Check(myName()) {} CheckClass() : Check(myName()) {}
/** @brief Set of the STL types whose operator[] is not const */
static const std::set<std::string> stl_containers_not_const;
private:
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger); CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger);
@ -191,10 +199,6 @@ public:
/** @brief Analyse all file infos for all TU */ /** @brief Analyse all file infos for all TU */
bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override; bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override;
/** @brief Set of the STL types whose operator[] is not const */
static const std::set<std::string> stl_containers_not_const;
private:
const SymbolDatabase* mSymbolDatabase{}; const SymbolDatabase* mSymbolDatabase{};
// Reporting errors.. // Reporting errors..

View File

@ -48,10 +48,13 @@ namespace ValueFlow {
*/ */
class CPPCHECKLIB CheckCondition : public Check { class CPPCHECKLIB CheckCondition : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckAssignIf */ /** This constructor is used when registering the CheckAssignIf */
CheckCondition() : Check(myName()) {} CheckCondition() : Check(myName()) {}
private:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckCondition(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckCondition(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -128,7 +131,6 @@ public:
/** @brief Assignment in condition */ /** @brief Assignment in condition */
void checkAssignmentInCondition(); void checkAssignmentInCondition();
private:
// The conditions that have been diagnosed // The conditions that have been diagnosed
std::set<const Token*> mCondDiags; std::set<const Token*> mCondDiags;
bool diag(const Token* tok, bool insert=true); bool diag(const Token* tok, bool insert=true);

View File

@ -45,10 +45,13 @@ class Token;
*/ */
class CPPCHECKLIB CheckExceptionSafety : public Check { class CPPCHECKLIB CheckExceptionSafety : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckExceptionSafety() : Check(myName()) {} CheckExceptionSafety() : Check(myName()) {}
private:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckExceptionSafety(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckExceptionSafety(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -88,7 +91,6 @@ public:
/** @brief %Check for rethrow not from catch scope */ /** @brief %Check for rethrow not from catch scope */
void rethrowNoCurrentException(); void rethrowNoCurrentException();
private:
/** Don't throw exceptions in destructors */ /** Don't throw exceptions in destructors */
void destructorsError(const Token * const tok, const std::string &className); void destructorsError(const Token * const tok, const std::string &className);
void deallocThrowError(const Token * const tok, const std::string &varname); void deallocThrowError(const Token * const tok, const std::string &varname);

View File

@ -49,10 +49,14 @@ namespace ValueFlow {
*/ */
class CPPCHECKLIB CheckFunctions : public Check { class CPPCHECKLIB CheckFunctions : public Check {
friend class TestFunctions;
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckFunctions */ /** This constructor is used when registering the CheckFunctions */
CheckFunctions() : Check(myName()) {} CheckFunctions() : Check(myName()) {}
private:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -109,7 +113,6 @@ public:
/** @brief --check-library: warn for unconfigured function calls */ /** @brief --check-library: warn for unconfigured function calls */
void checkLibraryMatchFunctions(); void checkLibraryMatchFunctions();
private:
/** @brief %Check for missing "return" */ /** @brief %Check for missing "return" */
void checkMissingReturn(); void checkMissingReturn();

View File

@ -39,10 +39,12 @@ class Token;
/** @brief %Check Internal cppcheck API usage */ /** @brief %Check Internal cppcheck API usage */
class CPPCHECKLIB CheckInternal : public Check { class CPPCHECKLIB CheckInternal : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckInternal() : Check(myName()) {} CheckInternal() : Check(myName()) {}
private:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckInternal(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckInternal(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -82,7 +84,7 @@ public:
/** @brief %Check if there is a redundant check for none-nullness of parameter before Match functions, such as (tok && Token::Match(tok, "foo")) */ /** @brief %Check if there is a redundant check for none-nullness of parameter before Match functions, such as (tok && Token::Match(tok, "foo")) */
void checkRedundantTokCheck(); void checkRedundantTokCheck();
private:
void multiComparePatternError(const Token *tok, const std::string &pattern, const std::string &funcname); void multiComparePatternError(const Token *tok, const std::string &pattern, const std::string &funcname);
void simplePatternError(const Token *tok, const std::string &pattern, const std::string &funcname); void simplePatternError(const Token *tok, const std::string &pattern, const std::string &funcname);
void complexPatternError(const Token *tok, const std::string &pattern, const std::string &funcname); void complexPatternError(const Token *tok, const std::string &pattern, const std::string &funcname);

View File

@ -40,10 +40,13 @@ class ErrorLogger;
/** @brief %Check input output operations. */ /** @brief %Check input output operations. */
class CPPCHECKLIB CheckIO : public Check { class CPPCHECKLIB CheckIO : public Check {
friend class TestIO;
public: public:
/** @brief This constructor is used when registering CheckIO */ /** @brief This constructor is used when registering CheckIO */
CheckIO() : Check(myName()) {} CheckIO() : Check(myName()) {}
private:
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckIO(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckIO(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -70,7 +73,6 @@ public:
/** @brief %Checks type and number of arguments given to functions like printf or scanf*/ /** @brief %Checks type and number of arguments given to functions like printf or scanf*/
void checkWrongPrintfScanfArguments(); void checkWrongPrintfScanfArguments();
private:
class ArgumentInfo { class ArgumentInfo {
public: public:
ArgumentInfo(const Token *arg, const Settings *settings, bool _isCPP); ArgumentInfo(const Token *arg, const Settings *settings, bool _isCPP);

View File

@ -107,10 +107,13 @@ public:
*/ */
class CPPCHECKLIB CheckLeakAutoVar : public Check { class CPPCHECKLIB CheckLeakAutoVar : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckLeakAutoVar */ /** This constructor is used when registering the CheckLeakAutoVar */
CheckLeakAutoVar() : Check(myName()) {} CheckLeakAutoVar() : Check(myName()) {}
private:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckLeakAutoVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckLeakAutoVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -120,8 +123,6 @@ public:
checkLeakAutoVar.check(); checkLeakAutoVar.check();
} }
private:
/** check for leaks in all scopes */ /** check for leaks in all scopes */
void check(); void check();

View File

@ -163,11 +163,14 @@ public:
* -# finally, check if the simplified token list contain any leaks. * -# finally, check if the simplified token list contain any leaks.
*/ */
class CPPCHECKLIB CheckMemoryLeakInFunction : private Check, public CheckMemoryLeak { class CPPCHECKLIB CheckMemoryLeakInFunction : public Check, public CheckMemoryLeak {
friend class TestMemleakInFunction;
public: public:
/** @brief This constructor is used when registering this class */ /** @brief This constructor is used when registering this class */
CheckMemoryLeakInFunction() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {} CheckMemoryLeakInFunction() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {}
private:
/** @brief This constructor is used when running checks */ /** @brief This constructor is used when running checks */
CheckMemoryLeakInFunction(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckMemoryLeakInFunction(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {} : Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {}
@ -182,7 +185,6 @@ public:
*/ */
void checkReallocUsage(); void checkReallocUsage();
private:
/** Report all possible errors (for the --errorlist) */ /** Report all possible errors (for the --errorlist) */
void getErrorMessages(ErrorLogger *e, const Settings *settings) const override { void getErrorMessages(ErrorLogger *e, const Settings *settings) const override {
CheckMemoryLeakInFunction c(nullptr, settings, e); CheckMemoryLeakInFunction c(nullptr, settings, e);
@ -217,10 +219,13 @@ private:
* @brief %Check class variables, variables that are allocated in the constructor should be deallocated in the destructor * @brief %Check class variables, variables that are allocated in the constructor should be deallocated in the destructor
*/ */
class CPPCHECKLIB CheckMemoryLeakInClass : private Check, private CheckMemoryLeak { class CPPCHECKLIB CheckMemoryLeakInClass : public Check, private CheckMemoryLeak {
friend class TestMemleakInClass;
public: public:
CheckMemoryLeakInClass() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {} CheckMemoryLeakInClass() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {}
private:
CheckMemoryLeakInClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckMemoryLeakInClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {} : Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {}
@ -234,7 +239,6 @@ public:
void check(); void check();
private:
void variable(const Scope *scope, const Token *tokVarname); void variable(const Scope *scope, const Token *tokVarname);
/** Public functions: possible double-allocation */ /** Public functions: possible double-allocation */
@ -262,10 +266,13 @@ private:
/** @brief detect simple memory leaks for struct members */ /** @brief detect simple memory leaks for struct members */
class CPPCHECKLIB CheckMemoryLeakStructMember : private Check, private CheckMemoryLeak { class CPPCHECKLIB CheckMemoryLeakStructMember : public Check, private CheckMemoryLeak {
friend class TestMemleakStructMember;
public: public:
CheckMemoryLeakStructMember() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {} CheckMemoryLeakStructMember() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {}
private:
CheckMemoryLeakStructMember(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckMemoryLeakStructMember(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {} : Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {}
@ -276,8 +283,6 @@ public:
void check(); void check();
private:
/** Is local variable allocated with malloc? */ /** Is local variable allocated with malloc? */
bool isMalloc(const Variable *variable) const; bool isMalloc(const Variable *variable) const;
@ -298,10 +303,13 @@ private:
/** @brief detect simple memory leaks (address not taken) */ /** @brief detect simple memory leaks (address not taken) */
class CPPCHECKLIB CheckMemoryLeakNoVar : private Check, private CheckMemoryLeak { class CPPCHECKLIB CheckMemoryLeakNoVar : public Check, private CheckMemoryLeak {
friend class TestMemleakNoVar;
public: public:
CheckMemoryLeakNoVar() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {} CheckMemoryLeakNoVar() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {}
private:
CheckMemoryLeakNoVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckMemoryLeakNoVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {} : Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {}
@ -312,7 +320,6 @@ public:
void check(); void check();
private:
/** /**
* @brief %Check if an input argument to a function is the return value of an allocation function * @brief %Check if an input argument to a function is the return value of an allocation function
* like malloc(), and the function does not release it. * like malloc(), and the function does not release it.

View File

@ -47,32 +47,13 @@ namespace tinyxml2 {
/** @brief check for null pointer dereferencing */ /** @brief check for null pointer dereferencing */
class CPPCHECKLIB CheckNullPointer : public Check { class CPPCHECKLIB CheckNullPointer : public Check {
friend class TestNullPointer;
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckNullPointer */ /** @brief This constructor is used when registering the CheckNullPointer */
CheckNullPointer() : Check(myName()) {} CheckNullPointer() : Check(myName()) {}
/** @brief This constructor is used when running checks. */
CheckNullPointer(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}
/** @brief Run checks against the normal token list */
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckNullPointer checkNullPointer(&tokenizer, tokenizer.getSettings(), errorLogger);
checkNullPointer.nullPointer();
checkNullPointer.arithmetic();
checkNullPointer.nullConstantDereference();
}
/**
* @brief parse a function call and extract information about variable usage
* @param tok first token
* @param var variables that the function read / write.
* @param library --library files data
*/
static void parseFunctionCall(const Token &tok,
std::list<const Token *> &var,
const Library *library);
/** /**
* Is there a pointer dereference? Everything that should result in * Is there a pointer dereference? Everything that should result in
* a nullpointer dereference error message will result in a true * a nullpointer dereference error message will result in a true
@ -86,6 +67,29 @@ public:
static bool isPointerDeRef(const Token *tok, bool &unknown, const Settings *settings); static bool isPointerDeRef(const Token *tok, bool &unknown, const Settings *settings);
private:
/**
* @brief parse a function call and extract information about variable usage
* @param tok first token
* @param var variables that the function read / write.
* @param library --library files data
*/
static void parseFunctionCall(const Token &tok,
std::list<const Token *> &var,
const Library *library);
/** @brief This constructor is used when running checks. */
CheckNullPointer(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}
/** @brief Run checks against the normal token list */
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckNullPointer checkNullPointer(&tokenizer, tokenizer.getSettings(), errorLogger);
checkNullPointer.nullPointer();
checkNullPointer.arithmetic();
checkNullPointer.nullConstantDereference();
}
/** @brief possible null pointer dereference */ /** @brief possible null pointer dereference */
void nullPointer(); void nullPointer();
@ -117,7 +121,6 @@ public:
/** @brief Analyse all file infos for all TU */ /** @brief Analyse all file infos for all TU */
bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override; bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override;
private:
/** Get error messages. Used by --errorlist */ /** Get error messages. Used by --errorlist */
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
CheckNullPointer c(nullptr, settings, errorLogger); CheckNullPointer c(nullptr, settings, errorLogger);

View File

@ -47,14 +47,27 @@ class ErrorLogger;
/** @brief Various small checks */ /** @brief Various small checks */
class CPPCHECKLIB CheckOther : public Check { class CPPCHECKLIB CheckOther : public Check {
friend class TestCharVar;
friend class TestIncompleteStatement;
friend class TestOther;
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckOther() : Check(myName()) {} CheckOther() : Check(myName()) {}
/** Is expression a comparison that checks if a nonzero (unsigned/pointer) expression is less than zero? */
static bool comparisonNonZeroExpressionLessThanZero(const Token *tok, const ValueFlow::Value **zeroValue, const Token **nonZeroExpr);
/** Is expression a comparison that checks if a nonzero (unsigned/pointer) expression is positive? */
static bool testIfNonZeroExpressionIsPositive(const Token *tok, const ValueFlow::Value **zeroValue, const Token **nonZeroExpr);
private:
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
/** @brief Run checks against the normal token list */ /** @brief Run checks against the normal token list */
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override { void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckOther checkOther(&tokenizer, tokenizer.getSettings(), errorLogger); CheckOther checkOther(&tokenizer, tokenizer.getSettings(), errorLogger);
@ -103,13 +116,6 @@ public:
checkOther.checkOverlappingWrite(); checkOther.checkOverlappingWrite();
} }
/** Is expression a comparison that checks if a nonzero (unsigned/pointer) expression is less than zero? */
static bool comparisonNonZeroExpressionLessThanZero(const Token *tok, const ValueFlow::Value **zeroValue, const Token **nonZeroExpr);
/** Is expression a comparison that checks if a nonzero (unsigned/pointer) expression is positive? */
static bool testIfNonZeroExpressionIsPositive(const Token *tok, const ValueFlow::Value **zeroValue, const Token **nonZeroExpr);
/** @brief Clarify calculation for ".. a * b ? .." */ /** @brief Clarify calculation for ".. a * b ? .." */
void clarifyCalculation(); void clarifyCalculation();
@ -229,7 +235,6 @@ public:
void overlappingWriteUnion(const Token *tok); void overlappingWriteUnion(const Token *tok);
void overlappingWriteFunction(const Token *tok); void overlappingWriteFunction(const Token *tok);
private:
// Error messages.. // Error messages..
void checkComparisonFunctionIsAlwaysTrueOrFalseError(const Token* tok, const std::string &functionName, const std::string &varName, const bool result); void checkComparisonFunctionIsAlwaysTrueOrFalseError(const Token* tok, const std::string &functionName, const std::string &varName, const bool result);
void checkCastIntToCharAndBackError(const Token *tok, const std::string &strFunctionName); void checkCastIntToCharAndBackError(const Token *tok, const std::string &strFunctionName);

View File

@ -40,10 +40,13 @@ class Token;
*/ */
class CPPCHECKLIB CheckPostfixOperator : public Check { class CPPCHECKLIB CheckPostfixOperator : public Check {
friend class TestPostfixOperator;
public: public:
/** This constructor is used when registering the CheckPostfixOperator */ /** This constructor is used when registering the CheckPostfixOperator */
CheckPostfixOperator() : Check(myName()) {} CheckPostfixOperator() : Check(myName()) {}
private:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckPostfixOperator(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckPostfixOperator(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -59,7 +62,6 @@ public:
/** Check postfix operators */ /** Check postfix operators */
void postfixOperator(); void postfixOperator();
private:
/** Report Error */ /** Report Error */
void postfixOperatorError(const Token *tok); void postfixOperatorError(const Token *tok);

View File

@ -39,10 +39,13 @@ class Token;
/** @brief checks on usage of sizeof() operator */ /** @brief checks on usage of sizeof() operator */
class CPPCHECKLIB CheckSizeof : public Check { class CPPCHECKLIB CheckSizeof : public Check {
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckSizeof() : Check(myName()) {} CheckSizeof() : Check(myName()) {}
private:
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckSizeof(const Tokenizer* tokenizer, const Settings* settings, ErrorLogger* errorLogger) CheckSizeof(const Tokenizer* tokenizer, const Settings* settings, ErrorLogger* errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -86,7 +89,6 @@ public:
/** @brief %Check for using sizeof(void) */ /** @brief %Check for using sizeof(void) */
void sizeofVoid(); void sizeofVoid();
private:
// Error messages.. // Error messages..
void sizeofsizeofError(const Token* tok); void sizeofsizeofError(const Token* tok);
void sizeofCalculationError(const Token* tok, bool inconclusive); void sizeofCalculationError(const Token* tok, bool inconclusive);

View File

@ -43,10 +43,13 @@ class ErrorLogger;
/** @brief %Check STL usage (invalidation of iterators, mismatching containers, etc) */ /** @brief %Check STL usage (invalidation of iterators, mismatching containers, etc) */
class CPPCHECKLIB CheckStl : public Check { class CPPCHECKLIB CheckStl : public Check {
friend class TestFixture;
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckStl() : Check(myName()) {} CheckStl() : Check(myName()) {}
private:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckStl(const Tokenizer* tokenizer, const Settings* settings, ErrorLogger* errorLogger) CheckStl(const Tokenizer* tokenizer, const Settings* settings, ErrorLogger* errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -184,7 +187,6 @@ public:
void checkMutexes(); void checkMutexes();
private:
bool isContainerSize(const Token *containerToken, const Token *expr) const; bool isContainerSize(const Token *containerToken, const Token *expr) const;
bool isContainerSizeGE(const Token * containerToken, const Token *expr) const; bool isContainerSizeGE(const Token * containerToken, const Token *expr) const;

View File

@ -39,10 +39,13 @@ class Token;
/** @brief Detect misusage of C-style strings and related standard functions */ /** @brief Detect misusage of C-style strings and related standard functions */
class CPPCHECKLIB CheckString : public Check { class CPPCHECKLIB CheckString : public Check {
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckString() : Check(myName()) {} CheckString() : Check(myName()) {}
private:
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckString(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckString(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -82,7 +85,6 @@ public:
/** @brief %Check for overlapping source and destination passed to sprintf() */ /** @brief %Check for overlapping source and destination passed to sprintf() */
void sprintfOverlappingData(); void sprintfOverlappingData();
private:
void stringLiteralWriteError(const Token *tok, const Token *strValue); void stringLiteralWriteError(const Token *tok, const Token *strValue);
void sprintfOverlappingDataError(const Token *funcTok, const Token *tok, const std::string &varname); void sprintfOverlappingDataError(const Token *funcTok, const Token *tok, const std::string &varname);
void strPlusCharError(const Token *tok); void strPlusCharError(const Token *tok);

View File

@ -42,10 +42,13 @@ class ValueType;
/** @brief Various small checks */ /** @brief Various small checks */
class CPPCHECKLIB CheckType : public Check { class CPPCHECKLIB CheckType : public Check {
friend class TestFixture;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckType() : Check(myName()) {} CheckType() : Check(myName()) {}
private:
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckType(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckType(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -77,8 +80,6 @@ public:
void checkFloatToIntegerOverflow(); void checkFloatToIntegerOverflow();
void checkFloatToIntegerOverflow(const Token *tok, const ValueType *vtint, const ValueType *vtfloat, const std::list<ValueFlow::Value> &floatValues); void checkFloatToIntegerOverflow(const Token *tok, const ValueType *vtint, const ValueType *vtfloat, const std::list<ValueFlow::Value> &floatValues);
private:
// Error messages.. // Error messages..
void tooBigBitwiseShiftError(const Token *tok, int lhsbits, const ValueFlow::Value &rhsbits); void tooBigBitwiseShiftError(const Token *tok, int lhsbits, const ValueFlow::Value &rhsbits);
void tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, const ValueFlow::Value &rhsbits); void tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, const ValueFlow::Value &rhsbits);

View File

@ -60,10 +60,18 @@ struct VariableValue {
/** @brief Checking for uninitialized variables */ /** @brief Checking for uninitialized variables */
class CPPCHECKLIB CheckUninitVar : public Check { class CPPCHECKLIB CheckUninitVar : public Check {
friend class TestUninitVar;
public: public:
/** @brief This constructor is used when registering the CheckUninitVar */ /** @brief This constructor is used when registering the CheckUninitVar */
CheckUninitVar() : Check(myName()) {} CheckUninitVar() : Check(myName()) {}
enum Alloc { NO_ALLOC, NO_CTOR_CALL, CTOR_CALL, ARRAY };
static const Token *isVariableUsage(bool cpp, const Token *vartok, const Library &library, bool pointer, Alloc alloc, int indirect = 0);
const Token *isVariableUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect = 0) const;
private:
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckUninitVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckUninitVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -80,15 +88,12 @@ public:
void check(); void check();
void checkScope(const Scope* scope, const std::set<std::string> &arrayTypeDefs); void checkScope(const Scope* scope, const std::set<std::string> &arrayTypeDefs);
void checkStruct(const Token *tok, const Variable &structvar); void checkStruct(const Token *tok, const Variable &structvar);
enum Alloc { NO_ALLOC, NO_CTOR_CALL, CTOR_CALL, ARRAY };
bool checkScopeForVariable(const Token *tok, const Variable& var, bool* const possibleInit, bool* const noreturn, Alloc* const alloc, const std::string &membervar, std::map<nonneg int, VariableValue> variableValue); bool checkScopeForVariable(const Token *tok, const Variable& var, bool* const possibleInit, bool* const noreturn, Alloc* const alloc, const std::string &membervar, std::map<nonneg int, VariableValue> variableValue);
const Token* checkExpr(const Token* tok, const Variable& var, const Alloc alloc, bool known, bool* bailout = nullptr) const; const Token* checkExpr(const Token* tok, const Variable& var, const Alloc alloc, bool known, bool* bailout = nullptr) const;
bool checkIfForWhileHead(const Token *startparentheses, const Variable& var, bool suppressErrors, bool isuninit, Alloc alloc, const std::string &membervar); bool checkIfForWhileHead(const Token *startparentheses, const Variable& var, bool suppressErrors, bool isuninit, Alloc alloc, const std::string &membervar);
bool checkLoopBody(const Token *tok, const Variable& var, const Alloc alloc, const std::string &membervar, const bool suppressErrors); bool checkLoopBody(const Token *tok, const Variable& var, const Alloc alloc, const std::string &membervar, const bool suppressErrors);
const Token* checkLoopBodyRecursive(const Token *start, const Variable& var, const Alloc alloc, const std::string &membervar, bool &bailout) const; const Token* checkLoopBodyRecursive(const Token *start, const Variable& var, const Alloc alloc, const std::string &membervar, bool &bailout) const;
void checkRhs(const Token *tok, const Variable &var, Alloc alloc, nonneg int number_of_if, const std::string &membervar); void checkRhs(const Token *tok, const Variable &var, Alloc alloc, nonneg int number_of_if, const std::string &membervar);
static const Token *isVariableUsage(bool cpp, const Token *vartok, const Library &library, bool pointer, Alloc alloc, int indirect = 0);
const Token *isVariableUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect = 0) const;
static int isFunctionParUsage(const Token *vartok, const Library &library, bool pointer, Alloc alloc, int indirect = 0); static int isFunctionParUsage(const Token *vartok, const Library &library, bool pointer, Alloc alloc, int indirect = 0);
int isFunctionParUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect = 0) const; int isFunctionParUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect = 0) const;
bool isMemberVariableAssignment(const Token *tok, const std::string &membervar) const; bool isMemberVariableAssignment(const Token *tok, const std::string &membervar) const;
@ -130,7 +135,6 @@ public:
} }
void uninitStructMemberError(const Token *tok, const std::string &membername); void uninitStructMemberError(const Token *tok, const std::string &membername);
private:
std::set<const Token*> mUninitDiags; std::set<const Token*> mUninitDiags;
Check::FileInfo* getFileInfo() const; Check::FileInfo* getFileInfo() const;

View File

@ -49,10 +49,10 @@ namespace CTU {
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Register this check class // Register this check class
CheckUnusedFunctions CheckUnusedFunctions::instance; namespace {
CheckUnusedFunctions instance;
}
static const struct CWE CWE561(561U); // Dead Code static const struct CWE CWE561(561U); // Dead Code
@ -68,6 +68,12 @@ static std::string stripTemplateParameters(const std::string& funcName) {
// FUNCTION USAGE - Check for unused functions etc // FUNCTION USAGE - Check for unused functions etc
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckUnusedFunctions::clear()
{
instance.mFunctions.clear();
instance.mFunctionCalls.clear();
}
void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char FileName[], const Settings *settings) void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char FileName[], const Settings *settings)
{ {
const bool doMarkup = settings->library.markupFile(FileName); const bool doMarkup = settings->library.markupFile(FileName);

View File

@ -44,6 +44,8 @@ namespace CTU {
/// @{ /// @{
class CPPCHECKLIB CheckUnusedFunctions : public Check { class CPPCHECKLIB CheckUnusedFunctions : public Check {
friend class TestUnusedFunctions;
public: public:
/** @brief This constructor is used when registering the CheckUnusedFunctions */ /** @brief This constructor is used when registering the CheckUnusedFunctions */
CheckUnusedFunctions() : Check(myName()) {} CheckUnusedFunctions() : Check(myName()) {}
@ -52,10 +54,7 @@ public:
CheckUnusedFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckUnusedFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
static void clear() { static void clear();
instance.mFunctions.clear();
instance.mFunctionCalls.clear();
}
// Parse current tokens and determine.. // Parse current tokens and determine..
// * Check what functions are used // * Check what functions are used
@ -71,15 +70,12 @@ public:
/** @brief Analyse all file infos for all TU */ /** @brief Analyse all file infos for all TU */
bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override; bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override;
static CheckUnusedFunctions instance;
std::string analyzerInfo() const; std::string analyzerInfo() const;
/** @brief Combine and analyze all analyzerInfos for all TUs */ /** @brief Combine and analyze all analyzerInfos for all TUs */
static void analyseWholeProgram(const Settings &settings, ErrorLogger * const errorLogger, const std::string &buildDir); static void analyseWholeProgram(const Settings &settings, ErrorLogger * const errorLogger, const std::string &buildDir);
private: private:
void getErrorMessages(ErrorLogger *errorLogger, const Settings * /*settings*/) const override { void getErrorMessages(ErrorLogger *errorLogger, const Settings * /*settings*/) const override {
CheckUnusedFunctions::unusedFunctionError(errorLogger, emptyString, 0, "funcName"); CheckUnusedFunctions::unusedFunctionError(errorLogger, emptyString, 0, "funcName");
} }

View File

@ -45,10 +45,13 @@ class Function;
/** @brief Various small checks */ /** @brief Various small checks */
class CPPCHECKLIB CheckUnusedVar : public Check { class CPPCHECKLIB CheckUnusedVar : public Check {
friend class TestUnusedVar;
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckUnusedVar() : Check(myName()) {} CheckUnusedVar() : Check(myName()) {}
private:
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckUnusedVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckUnusedVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -69,7 +72,6 @@ public:
/** @brief %Check that all struct members are used */ /** @brief %Check that all struct members are used */
void checkStructMemberUsage(); void checkStructMemberUsage();
private:
bool isRecordTypeWithoutSideEffects(const Type* type); bool isRecordTypeWithoutSideEffects(const Type* type);
bool isVariableWithoutSideEffects(const Variable& var); bool isVariableWithoutSideEffects(const Variable& var);
bool isEmptyType(const Type* type); bool isEmptyType(const Type* type);

View File

@ -40,9 +40,12 @@ class Token;
*/ */
class CPPCHECKLIB CheckVaarg : public Check { class CPPCHECKLIB CheckVaarg : public Check {
friend class TestFixture;
public: public:
CheckVaarg() : Check(myName()) {} CheckVaarg() : Check(myName()) {}
private:
CheckVaarg(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckVaarg(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {} : Check(myName(), tokenizer, settings, errorLogger) {}
@ -55,7 +58,6 @@ public:
void va_start_argument(); void va_start_argument();
void va_list_usage(); void va_list_usage();
private:
void wrongParameterTo_va_start_error(const Token *tok, const std::string& paramIsName, const std::string& paramShouldName); void wrongParameterTo_va_start_error(const Token *tok, const std::string& paramIsName, const std::string& paramShouldName);
void referenceAs_va_start_error(const Token *tok, const std::string& paramName); void referenceAs_va_start_error(const Token *tok, const std::string& paramName);
void va_end_missingError(const Token *tok, const std::string& varname); void va_end_missingError(const Token *tok, const std::string& varname);