Skip to content

Commit eba1b08

Browse files
committed
Minor refactoring: use nullptr (instead of 0/NULL), change signature of Tokenizer::createTokens
1 parent 5d5886b commit eba1b08

28 files changed

Lines changed: 292 additions & 294 deletions

lib/check64bit.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ class CPPCHECKLIB Check64BitPortability : public Check {
6868
void returnPointerError(const Token *tok);
6969

7070
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
71-
Check64BitPortability c(0, settings, errorLogger);
72-
c.assignmentAddressToIntegerError(0);
73-
c.assignmentIntegerToAddressError(0);
74-
c.returnIntegerError(0);
75-
c.returnPointerError(0);
71+
Check64BitPortability c(nullptr, settings, errorLogger);
72+
c.assignmentAddressToIntegerError(nullptr);
73+
c.assignmentIntegerToAddressError(nullptr);
74+
c.returnIntegerError(nullptr);
75+
c.returnPointerError(nullptr);
7676
}
7777

7878
static std::string myName() {

lib/checkassert.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class CPPCHECKLIB CheckAssert : public Check {
5757
void assignmentInAssertError(const Token *tok, const std::string &varname);
5858

5959
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
60-
CheckAssert c(0, settings, errorLogger);
61-
c.sideEffectInAssertError(0, "function");
62-
c.assignmentInAssertError(0, "var");
60+
CheckAssert c(nullptr, settings, errorLogger);
61+
c.sideEffectInAssertError(nullptr, "function");
62+
c.assignmentInAssertError(nullptr, "var");
6363
}
6464

6565
static std::string myName() {

lib/checkautovariables.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
9292
void errorUselessAssignmentPtrArg(const Token *tok);
9393

9494
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
95-
CheckAutoVariables c(0,settings,errorLogger);
96-
c.errorAutoVariableAssignment(0, false);
97-
c.errorReturnAddressToAutoVariable(0);
98-
c.errorReturnPointerToLocalArray(0);
99-
c.errorReturnReference(0);
100-
c.errorReturnTempReference(0);
101-
c.errorInvalidDeallocation(0);
102-
c.errorReturnAddressOfFunctionParameter(0, "parameter");
103-
c.errorUselessAssignmentArg(0);
104-
c.errorUselessAssignmentPtrArg(0);
95+
CheckAutoVariables c(nullptr,settings,errorLogger);
96+
c.errorAutoVariableAssignment(nullptr, false);
97+
c.errorReturnAddressToAutoVariable(nullptr);
98+
c.errorReturnPointerToLocalArray(nullptr);
99+
c.errorReturnReference(nullptr);
100+
c.errorReturnTempReference(nullptr);
101+
c.errorInvalidDeallocation(nullptr);
102+
c.errorReturnAddressOfFunctionParameter(nullptr, "parameter");
103+
c.errorUselessAssignmentArg(nullptr);
104+
c.errorUselessAssignmentPtrArg(nullptr);
105105
}
106106

107107
static std::string myName() {

lib/checkbool.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ class CPPCHECKLIB CheckBool : public Check {
110110
void pointerArithBoolError(const Token *tok);
111111

112112
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
113-
CheckBool c(0, settings, errorLogger);
114-
115-
c.assignBoolToPointerError(0);
116-
c.assignBoolToFloatError(0);
117-
c.comparisonOfFuncReturningBoolError(0, "func_name");
118-
c.comparisonOfTwoFuncsReturningBoolError(0, "func_name1", "func_name2");
119-
c.comparisonOfBoolWithBoolError(0, "var_name");
120-
c.incrementBooleanError(0);
121-
c.bitwiseOnBooleanError(0, "varname", "&&");
122-
c.comparisonOfBoolExpressionWithIntError(0, true);
123-
c.pointerArithBoolError(0);
113+
CheckBool c(nullptr, settings, errorLogger);
114+
115+
c.assignBoolToPointerError(nullptr);
116+
c.assignBoolToFloatError(nullptr);
117+
c.comparisonOfFuncReturningBoolError(nullptr, "func_name");
118+
c.comparisonOfTwoFuncsReturningBoolError(nullptr, "func_name1", "func_name2");
119+
c.comparisonOfBoolWithBoolError(nullptr, "var_name");
120+
c.incrementBooleanError(nullptr);
121+
c.bitwiseOnBooleanError(nullptr, "varname", "&&");
122+
c.comparisonOfBoolExpressionWithIntError(nullptr, true);
123+
c.pointerArithBoolError(nullptr);
124124
}
125125

126126
static std::string myName() {

lib/checkbufferoverrun.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -243,23 +243,23 @@ class CPPCHECKLIB CheckBufferOverrun : public Check {
243243

244244
public:
245245
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
246-
CheckBufferOverrun c(0, settings, errorLogger);
246+
CheckBufferOverrun c(nullptr, settings, errorLogger);
247247
const std::vector<MathLib::bigint> indexes(2, 1);
248-
c.arrayIndexOutOfBoundsError(0, ArrayInfo(0, "array", 1, 2), indexes);
249-
c.bufferOverrunError(0, std::string("buffer"));
250-
c.strncatUsageError(0);
251-
c.outOfBoundsError(0, "index", true, 2, 1);
252-
c.sizeArgumentAsCharError(0);
253-
c.terminateStrncpyError(0, "buffer");
254-
c.bufferNotZeroTerminatedError(0, "buffer", "strncpy");
255-
c.negativeIndexError(0, -1);
256-
c.cmdLineArgsError(0);
248+
c.arrayIndexOutOfBoundsError(nullptr, ArrayInfo(0, "array", 1, 2), indexes);
249+
c.bufferOverrunError(nullptr, std::string("buffer"));
250+
c.strncatUsageError(nullptr);
251+
c.outOfBoundsError(nullptr, "index", true, 2, 1);
252+
c.sizeArgumentAsCharError(nullptr);
253+
c.terminateStrncpyError(nullptr, "buffer");
254+
c.bufferNotZeroTerminatedError(nullptr, "buffer", "strncpy");
255+
c.negativeIndexError(nullptr, -1);
256+
c.cmdLineArgsError(nullptr);
257257
c.pointerOutOfBoundsError(nullptr, nullptr, 0);
258-
c.arrayIndexThenCheckError(0, "index");
259-
c.possibleBufferOverrunError(0, "source", "destination", false);
260-
c.argumentSizeError(0, "function", "array");
261-
c.negativeMemoryAllocationSizeError(0);
262-
c.negativeArraySizeError(0);
258+
c.arrayIndexThenCheckError(nullptr, "index");
259+
c.possibleBufferOverrunError(nullptr, "source", "destination", false);
260+
c.argumentSizeError(nullptr, "function", "array");
261+
c.negativeMemoryAllocationSizeError(nullptr);
262+
c.negativeArraySizeError(nullptr);
263263
c.reportError(nullptr, Severity::warning, "arrayIndexOutOfBoundsCond", "Array 'x[10]' accessed at index 20, which is out of bounds. Otherwise condition 'y==20' is redundant.", CWE119, false);
264264
}
265265
private:

lib/checkclass.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Function;
3535
class CPPCHECKLIB CheckClass : public Check {
3636
public:
3737
/** @brief This constructor is used when registering the CheckClass */
38-
CheckClass() : Check(myName()), symbolDatabase(NULL) {
38+
CheckClass() : Check(myName()), symbolDatabase(nullptr) {
3939
}
4040

4141
/** @brief This constructor is used when running checks. */
@@ -169,33 +169,33 @@ class CPPCHECKLIB CheckClass : public Check {
169169
void duplInheritedMembersError(const Token* tok1, const Token* tok2, const std::string &derivedname, const std::string &basename, const std::string &variablename, bool derivedIsStruct, bool baseIsStruct);
170170

171171
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
172-
CheckClass c(0, settings, errorLogger);
173-
c.noConstructorError(0, "classname", false);
174-
c.noExplicitConstructorError(0, "classname", false);
175-
//c.copyConstructorMallocError(0, 0, "var");
176-
c.copyConstructorShallowCopyError(0, "var");
177-
c.noCopyConstructorError(0, "class", false);
178-
c.uninitVarError(0, "classname", "varname", false);
179-
c.operatorEqVarError(0, "classname", "", false);
180-
c.unusedPrivateFunctionError(0, "classname", "funcname");
181-
c.memsetError(0, "memfunc", "classname", "class");
182-
c.memsetErrorReference(0, "memfunc", "class");
183-
c.memsetErrorFloat(0, "class");
184-
c.mallocOnClassWarning(0, "malloc", 0);
185-
c.mallocOnClassError(0, "malloc", 0, "std::string");
186-
c.operatorEqReturnError(0, "class");
187-
c.virtualDestructorError(0, "Base", "Derived", false);
188-
c.thisSubtractionError(0);
189-
c.operatorEqRetRefThisError(0);
190-
c.operatorEqMissingReturnStatementError(0, true);
191-
c.operatorEqShouldBeLeftUnimplementedError(0);
192-
c.operatorEqToSelfError(0);
193-
c.checkConstError(0, "class", "function", false);
194-
c.checkConstError(0, "class", "function", true);
195-
c.initializerListError(0, 0, "class", "variable");
196-
c.suggestInitializationList(0, "variable");
197-
c.selfInitializationError(0, "var");
198-
c.duplInheritedMembersError(0, 0, "class", "class", "variable", false, false);
172+
CheckClass c(nullptr, settings, errorLogger);
173+
c.noConstructorError(nullptr, "classname", false);
174+
c.noExplicitConstructorError(nullptr, "classname", false);
175+
//c.copyConstructorMallocError(nullptr, 0, "var");
176+
c.copyConstructorShallowCopyError(nullptr, "var");
177+
c.noCopyConstructorError(nullptr, "class", false);
178+
c.uninitVarError(nullptr, "classname", "varname", false);
179+
c.operatorEqVarError(nullptr, "classname", "", false);
180+
c.unusedPrivateFunctionError(nullptr, "classname", "funcname");
181+
c.memsetError(nullptr, "memfunc", "classname", "class");
182+
c.memsetErrorReference(nullptr, "memfunc", "class");
183+
c.memsetErrorFloat(nullptr, "class");
184+
c.mallocOnClassWarning(nullptr, "malloc", 0);
185+
c.mallocOnClassError(nullptr, "malloc", 0, "std::string");
186+
c.operatorEqReturnError(nullptr, "class");
187+
c.virtualDestructorError(nullptr, "Base", "Derived", false);
188+
c.thisSubtractionError(nullptr);
189+
c.operatorEqRetRefThisError(nullptr);
190+
c.operatorEqMissingReturnStatementError(nullptr, true);
191+
c.operatorEqShouldBeLeftUnimplementedError(nullptr);
192+
c.operatorEqToSelfError(nullptr);
193+
c.checkConstError(nullptr, "class", "function", false);
194+
c.checkConstError(nullptr, "class", "function", true);
195+
c.initializerListError(nullptr, 0, "class", "variable");
196+
c.suggestInitializationList(nullptr, "variable");
197+
c.selfInitializationError(nullptr, "var");
198+
c.duplInheritedMembersError(nullptr, 0, "class", "class", "variable", false, false);
199199
}
200200

201201
static std::string myName() {

lib/checkcondition.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,20 @@ class CPPCHECKLIB CheckCondition : public Check {
129129
void invalidTestForOverflow(const Token* tok, bool result);
130130

131131
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
132-
CheckCondition c(0, settings, errorLogger);
133-
134-
c.assignIfError(0, 0, "", false);
135-
c.badBitmaskCheckError(0);
136-
c.comparisonError(0, "&", 6, "==", 1, false);
137-
c.multiConditionError(0,1);
138-
c.mismatchingBitAndError(0, 0xf0, 0, 1);
139-
c.oppositeInnerConditionError(0, 0);
140-
c.incorrectLogicOperatorError(0, "foo > 3 && foo < 4", true);
141-
c.redundantConditionError(0, "If x > 11 the condition x > 10 is always true.");
142-
c.moduloAlwaysTrueFalseError(0, "1");
143-
c.clarifyConditionError(0, true, false);
144-
c.alwaysTrueFalseError(0, true);
145-
c.invalidTestForOverflow(0, false);
132+
CheckCondition c(nullptr, settings, errorLogger);
133+
134+
c.assignIfError(nullptr, 0, "", false);
135+
c.badBitmaskCheckError(nullptr);
136+
c.comparisonError(nullptr, "&", 6, "==", 1, false);
137+
c.multiConditionError(nullptr,1);
138+
c.mismatchingBitAndError(nullptr, 0xf0, 0, 1);
139+
c.oppositeInnerConditionError(nullptr, 0);
140+
c.incorrectLogicOperatorError(nullptr, "foo > 3 && foo < 4", true);
141+
c.redundantConditionError(nullptr, "If x > 11 the condition x > 10 is always true.");
142+
c.moduloAlwaysTrueFalseError(nullptr, "1");
143+
c.clarifyConditionError(nullptr, true, false);
144+
c.alwaysTrueFalseError(nullptr, true);
145+
c.invalidTestForOverflow(nullptr, false);
146146
}
147147

148148
static std::string myName() {

lib/checkexceptionsafety.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "config.h"
2525
#include "check.h"
26+
#include "utils.h"
2627

2728
// CWE ID used:
2829
static const struct CWE CWE398(398U); // Indicator of Poor Code Quality
@@ -119,9 +120,7 @@ class CPPCHECKLIB CheckExceptionSafety : public Check {
119120
/** Missing exception specification */
120121
void unhandledExceptionSpecificationError(const Token * const tok1, const Token * const tok2, const std::string & funcname) {
121122
std::string str1(tok1 ? tok1->str() : "foo");
122-
std::list<const Token*> locationList;
123-
locationList.push_back(tok1);
124-
locationList.push_back(tok2);
123+
const std::list<const Token*> locationList = make_container< std::list<const Token*> > () << tok1 << tok2;
125124
reportError(locationList, Severity::style, "unhandledExceptionSpecification",
126125
"Unhandled exception specification when calling function " + str1 + "().\n"
127126
"Unhandled exception specification when calling function " + str1 + "(). "
@@ -130,13 +129,13 @@ class CPPCHECKLIB CheckExceptionSafety : public Check {
130129

131130
/** Generate all possible errors (for --errorlist) */
132131
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
133-
CheckExceptionSafety c(0, settings, errorLogger);
134-
c.destructorsError(0, "Class");
135-
c.deallocThrowError(0, "p");
136-
c.rethrowCopyError(0, "varname");
137-
c.catchExceptionByValueError(0);
138-
c.noexceptThrowError(0);
139-
c.unhandledExceptionSpecificationError(0, 0, "funcname");
132+
CheckExceptionSafety c(nullptr, settings, errorLogger);
133+
c.destructorsError(nullptr, "Class");
134+
c.deallocThrowError(nullptr, "p");
135+
c.rethrowCopyError(nullptr, "varname");
136+
c.catchExceptionByValueError(nullptr);
137+
c.noexceptThrowError(nullptr);
138+
c.unhandledExceptionSpecificationError(nullptr, 0, "funcname");
140139
}
141140

142141
/** Short description of class (for --doc) */

lib/checkfunctions.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,17 @@ class CPPCHECKLIB CheckFunctions : public Check {
9595
void mathfunctionCallWarning(const Token *tok, const std::string& oldexp, const std::string& newexp);
9696

9797
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
98-
CheckFunctions c(0, settings, errorLogger);
98+
CheckFunctions c(nullptr, settings, errorLogger);
9999

100100
for (std::map<std::string, Library::WarnInfo>::const_iterator i = settings->library.functionwarn.cbegin(); i != settings->library.functionwarn.cend(); ++i) {
101-
c.reportError(0, Severity::style, i->first+"Called", i->second.message);
101+
c.reportError(nullptr, Severity::style, i->first+"Called", i->second.message);
102102
}
103103

104-
c.invalidFunctionArgError(0, "func_name", 1, "1-4");
105-
c.invalidFunctionArgBoolError(0, "func_name", 1);
106-
c.ignoredReturnValueError(0, "malloc");
107-
c.mathfunctionCallWarning(0);
108-
c.mathfunctionCallWarning(0, "1 - erf(x)", "erfc(x)");
104+
c.invalidFunctionArgError(nullptr, "func_name", 1, "1-4");
105+
c.invalidFunctionArgBoolError(nullptr, "func_name", 1);
106+
c.ignoredReturnValueError(nullptr, "malloc");
107+
c.mathfunctionCallWarning(nullptr);
108+
c.mathfunctionCallWarning(nullptr, "1 - erf(x)", "erfc(x)");
109109
}
110110

111111
static std::string myName() {

lib/checkinternal.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ class CPPCHECKLIB CheckInternal : public Check {
8585
void extraWhitespaceError(const Token *tok, const std::string &pattern, const std::string &funcname);
8686

8787
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
88-
CheckInternal c(0, settings, errorLogger);
89-
c.multiComparePatternError(0, ";|%type%", "Match");
90-
c.simplePatternError(0, "class {", "Match");
91-
c.complexPatternError(0, "%type% ( )", "Match");
92-
c.missingPercentCharacterError(0, "%num", "Match");
93-
c.unknownPatternError(0, "%typ");
94-
c.redundantNextPreviousError(0, "previous", "next");
95-
c.orInComplexPattern(0, "||", "Match");
96-
c.extraWhitespaceError(0, "%str% ", "Match");
88+
CheckInternal c(nullptr, settings, errorLogger);
89+
c.multiComparePatternError(nullptr, ";|%type%", "Match");
90+
c.simplePatternError(nullptr, "class {", "Match");
91+
c.complexPatternError(nullptr, "%type% ( )", "Match");
92+
c.missingPercentCharacterError(nullptr, "%num", "Match");
93+
c.unknownPatternError(nullptr, "%typ");
94+
c.redundantNextPreviousError(nullptr, "previous", "next");
95+
c.orInComplexPattern(nullptr, "||", "Match");
96+
c.extraWhitespaceError(nullptr, "%str% ", "Match");
9797
}
9898

9999
static std::string myName() {

0 commit comments

Comments
 (0)