Skip to content

Commit f060293

Browse files
committed
moved runChecks() and getErrorMessages() implementions of checks into source files
1 parent 32a37f4 commit f060293

48 files changed

Lines changed: 879 additions & 723 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/check64bit.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,18 @@ void Check64BitPortability::returnIntegerError(const Token *tok)
161161
"and Linux they are of different width. In worst case you end up casting 64-bit integer down to 32-bit pointer. "
162162
"The safe way is to always return a pointer.", CWE758, Certainty::normal);
163163
}
164+
165+
void Check64BitPortability::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
166+
{
167+
Check64BitPortability check64BitPortability(&tokenizer, &tokenizer.getSettings(), errorLogger);
168+
check64BitPortability.pointerassignment();
169+
}
170+
171+
void Check64BitPortability::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
172+
{
173+
Check64BitPortability c(nullptr, settings, errorLogger);
174+
c.assignmentAddressToIntegerError(nullptr);
175+
c.assignmentIntegerToAddressError(nullptr);
176+
c.returnIntegerError(nullptr);
177+
c.returnPointerError(nullptr);
178+
}

lib/check64bit.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ class CPPCHECKLIB Check64BitPortability : public Check {
5353
: Check(myName(), tokenizer, settings, errorLogger) {}
5454

5555
/** @brief Run checks against the normal token list */
56-
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
57-
Check64BitPortability check64BitPortability(&tokenizer, &tokenizer.getSettings(), errorLogger);
58-
check64BitPortability.pointerassignment();
59-
}
56+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override;
6057

6158
/** Check for pointer assignment */
6259
void pointerassignment();
@@ -66,13 +63,7 @@ class CPPCHECKLIB Check64BitPortability : public Check {
6663
void returnIntegerError(const Token *tok);
6764
void returnPointerError(const Token *tok);
6865

69-
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
70-
Check64BitPortability c(nullptr, settings, errorLogger);
71-
c.assignmentAddressToIntegerError(nullptr);
72-
c.assignmentIntegerToAddressError(nullptr);
73-
c.returnIntegerError(nullptr);
74-
c.returnPointerError(nullptr);
75-
}
66+
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override;
7667

7768
static std::string myName() {
7869
return "64-bit portability";

lib/checkassert.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,16 @@ bool CheckAssert::inSameScope(const Token* returnTok, const Token* assignTok)
180180
// TODO: even if a return is in the same scope, the assignment might not affect it.
181181
return returnTok->scope() == assignTok->scope();
182182
}
183+
184+
void CheckAssert::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
185+
{
186+
CheckAssert checkAssert(&tokenizer, &tokenizer.getSettings(), errorLogger);
187+
checkAssert.assertWithSideEffects();
188+
}
189+
190+
void CheckAssert::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
191+
{
192+
CheckAssert c(nullptr, settings, errorLogger);
193+
c.sideEffectInAssertError(nullptr, "function");
194+
c.assignmentInAssertError(nullptr, "var");
195+
}

lib/checkassert.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ class CPPCHECKLIB CheckAssert : public Check {
4949
: Check(myName(), tokenizer, settings, errorLogger) {}
5050

5151
/** run checks, the token list is not simplified */
52-
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
53-
CheckAssert checkAssert(&tokenizer, &tokenizer.getSettings(), errorLogger);
54-
checkAssert.assertWithSideEffects();
55-
}
52+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override;
5653

5754
void assertWithSideEffects();
5855

@@ -62,11 +59,7 @@ class CPPCHECKLIB CheckAssert : public Check {
6259
void sideEffectInAssertError(const Token *tok, const std::string& functionName);
6360
void assignmentInAssertError(const Token *tok, const std::string &varname);
6461

65-
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
66-
CheckAssert c(nullptr, settings, errorLogger);
67-
c.sideEffectInAssertError(nullptr, "function");
68-
c.assignmentInAssertError(nullptr, "var");
69-
}
62+
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override;
7063

7164
static std::string myName() {
7265
return "Assert";

lib/checkautovariables.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,3 +787,28 @@ void CheckAutoVariables::errorInvalidDeallocation(const Token *tok, const ValueF
787787
"The deallocation of " + type + " results in undefined behaviour. You should only free memory "
788788
"that has been allocated dynamically.", CWE590, Certainty::normal);
789789
}
790+
791+
void CheckAutoVariables::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
792+
{
793+
CheckAutoVariables checkAutoVariables(&tokenizer, &tokenizer.getSettings(), errorLogger);
794+
checkAutoVariables.assignFunctionArg();
795+
checkAutoVariables.checkVarLifetime();
796+
checkAutoVariables.autoVariables();
797+
}
798+
799+
void CheckAutoVariables::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
800+
{
801+
CheckAutoVariables c(nullptr,settings,errorLogger);
802+
c.errorAutoVariableAssignment(nullptr, false);
803+
c.errorReturnReference(nullptr, ErrorPath{}, false);
804+
c.errorDanglingReference(nullptr, nullptr, ErrorPath{});
805+
c.errorReturnTempReference(nullptr, ErrorPath{}, false);
806+
c.errorDanglingTempReference(nullptr, ErrorPath{}, false);
807+
c.errorInvalidDeallocation(nullptr, nullptr);
808+
c.errorUselessAssignmentArg(nullptr);
809+
c.errorUselessAssignmentPtrArg(nullptr);
810+
c.errorReturnDanglingLifetime(nullptr, nullptr);
811+
c.errorInvalidLifetime(nullptr, nullptr);
812+
c.errorDanglngLifetime(nullptr, nullptr);
813+
c.errorDanglingTemporaryLifetime(nullptr, nullptr, nullptr);
814+
}

lib/checkautovariables.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,7 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
5555
: Check(myName(), tokenizer, settings, errorLogger) {}
5656

5757
/** @brief Run checks against the normal token list */
58-
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
59-
CheckAutoVariables checkAutoVariables(&tokenizer, &tokenizer.getSettings(), errorLogger);
60-
checkAutoVariables.assignFunctionArg();
61-
checkAutoVariables.checkVarLifetime();
62-
checkAutoVariables.autoVariables();
63-
}
58+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override;
6459

6560
/** assign function argument */
6661
void assignFunctionArg();
@@ -90,21 +85,7 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
9085
void errorUselessAssignmentArg(const Token *tok);
9186
void errorUselessAssignmentPtrArg(const Token *tok);
9287

93-
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
94-
CheckAutoVariables c(nullptr,settings,errorLogger);
95-
c.errorAutoVariableAssignment(nullptr, false);
96-
c.errorReturnReference(nullptr, ErrorPath{}, false);
97-
c.errorDanglingReference(nullptr, nullptr, ErrorPath{});
98-
c.errorReturnTempReference(nullptr, ErrorPath{}, false);
99-
c.errorDanglingTempReference(nullptr, ErrorPath{}, false);
100-
c.errorInvalidDeallocation(nullptr, nullptr);
101-
c.errorUselessAssignmentArg(nullptr);
102-
c.errorUselessAssignmentPtrArg(nullptr);
103-
c.errorReturnDanglingLifetime(nullptr, nullptr);
104-
c.errorInvalidLifetime(nullptr, nullptr);
105-
c.errorDanglngLifetime(nullptr, nullptr);
106-
c.errorDanglingTemporaryLifetime(nullptr, nullptr, nullptr);
107-
}
88+
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override;
10889

10990
static std::string myName() {
11091
return "Auto Variables";

lib/checkbool.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,36 @@ void CheckBool::returnValueBoolError(const Token *tok)
517517
{
518518
reportError(tok, Severity::style, "returnNonBoolInBooleanFunction", "Non-boolean value returned from function returning bool");
519519
}
520+
521+
void CheckBool::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
522+
{
523+
CheckBool checkBool(&tokenizer, &tokenizer.getSettings(), errorLogger);
524+
525+
// Checks
526+
checkBool.checkComparisonOfBoolExpressionWithInt();
527+
checkBool.checkComparisonOfBoolWithInt();
528+
checkBool.checkAssignBoolToFloat();
529+
checkBool.pointerArithBool();
530+
checkBool.returnValueOfFunctionReturningBool();
531+
checkBool.checkComparisonOfFuncReturningBool();
532+
checkBool.checkComparisonOfBoolWithBool();
533+
checkBool.checkIncrementBoolean();
534+
checkBool.checkAssignBoolToPointer();
535+
checkBool.checkBitwiseOnBoolean();
536+
}
537+
538+
void CheckBool::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
539+
{
540+
CheckBool c(nullptr, settings, errorLogger);
541+
c.assignBoolToPointerError(nullptr);
542+
c.assignBoolToFloatError(nullptr);
543+
c.comparisonOfFuncReturningBoolError(nullptr, "func_name");
544+
c.comparisonOfTwoFuncsReturningBoolError(nullptr, "func_name1", "func_name2");
545+
c.comparisonOfBoolWithBoolError(nullptr, "var_name");
546+
c.incrementBooleanError(nullptr);
547+
c.bitwiseOnBooleanError(nullptr, "expression", "&&");
548+
c.comparisonOfBoolExpressionWithIntError(nullptr, true);
549+
c.pointerArithBoolError(nullptr);
550+
c.comparisonOfBoolWithInvalidComparator(nullptr, "expression");
551+
c.returnValueBoolError(nullptr);
552+
}

lib/checkbool.h

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,7 @@ class CPPCHECKLIB CheckBool : public Check {
4949
: Check(myName(), tokenizer, settings, errorLogger) {}
5050

5151
/** @brief Run checks against the normal token list */
52-
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
53-
CheckBool checkBool(&tokenizer, &tokenizer.getSettings(), errorLogger);
54-
55-
// Checks
56-
checkBool.checkComparisonOfBoolExpressionWithInt();
57-
checkBool.checkComparisonOfBoolWithInt();
58-
checkBool.checkAssignBoolToFloat();
59-
checkBool.pointerArithBool();
60-
checkBool.returnValueOfFunctionReturningBool();
61-
checkBool.checkComparisonOfFuncReturningBool();
62-
checkBool.checkComparisonOfBoolWithBool();
63-
checkBool.checkIncrementBoolean();
64-
checkBool.checkAssignBoolToPointer();
65-
checkBool.checkBitwiseOnBoolean();
66-
}
52+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override;
6753

6854
/** @brief %Check for comparison of function returning bool*/
6955
void checkComparisonOfFuncReturningBool();
@@ -109,20 +95,7 @@ class CPPCHECKLIB CheckBool : public Check {
10995
void pointerArithBoolError(const Token *tok);
11096
void returnValueBoolError(const Token *tok);
11197

112-
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
113-
CheckBool c(nullptr, settings, errorLogger);
114-
c.assignBoolToPointerError(nullptr);
115-
c.assignBoolToFloatError(nullptr);
116-
c.comparisonOfFuncReturningBoolError(nullptr, "func_name");
117-
c.comparisonOfTwoFuncsReturningBoolError(nullptr, "func_name1", "func_name2");
118-
c.comparisonOfBoolWithBoolError(nullptr, "var_name");
119-
c.incrementBooleanError(nullptr);
120-
c.bitwiseOnBooleanError(nullptr, "expression", "&&");
121-
c.comparisonOfBoolExpressionWithIntError(nullptr, true);
122-
c.pointerArithBoolError(nullptr);
123-
c.comparisonOfBoolWithInvalidComparator(nullptr, "expression");
124-
c.returnValueBoolError(nullptr);
125-
}
98+
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override;
12699

127100
static std::string myName() {
128101
return "Boolean";

lib/checkboost.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,18 @@ void CheckBoost::boostForeachError(const Token *tok)
6464
"BOOST_FOREACH caches the end() iterator. It's undefined behavior if you modify the container inside.", CWE664, Certainty::normal
6565
);
6666
}
67+
68+
void CheckBoost::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
69+
{
70+
if (!tokenizer.isCPP())
71+
return;
72+
73+
CheckBoost checkBoost(&tokenizer, &tokenizer.getSettings(), errorLogger);
74+
checkBoost.checkBoostForeachModification();
75+
}
76+
77+
void CheckBoost::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
78+
{
79+
CheckBoost c(nullptr, settings, errorLogger);
80+
c.boostForeachError(nullptr);
81+
}

lib/checkboost.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,14 @@ class CPPCHECKLIB CheckBoost : public Check {
4848
: Check(myName(), tokenizer, settings, errorLogger) {}
4949

5050
/** @brief Run checks against the normal token list */
51-
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
52-
if (!tokenizer.isCPP())
53-
return;
54-
55-
CheckBoost checkBoost(&tokenizer, &tokenizer.getSettings(), errorLogger);
56-
checkBoost.checkBoostForeachModification();
57-
}
51+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override;
5852

5953
/** @brief %Check for container modification while using the BOOST_FOREACH macro */
6054
void checkBoostForeachModification();
6155

6256
void boostForeachError(const Token *tok);
6357

64-
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
65-
CheckBoost c(nullptr, settings, errorLogger);
66-
c.boostForeachError(nullptr);
67-
}
58+
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override;
6859

6960
static std::string myName() {
7061
return "Boost usage";

0 commit comments

Comments
 (0)