Skip to content

Commit

Permalink
removed unnecessary Settings parameter from Check::runChecks() an…
Browse files Browse the repository at this point in the history
…d made `Tokenizer` a reference (danmar#5308)

There was no need for the `Tokenizer` parameter to be a pointer as it
could never be `nullptr` and was also dereferenced without checking
first.

As a reference to the `Settings` was already available via the
`Tokenizer` there was no need to pass it separately. In the production
code there will only be one instance of it but in the tests we could
have accidentally passed a different one.
  • Loading branch information
firewave committed Aug 18, 2023
1 parent 1bedf44 commit bfb50ca
Show file tree
Hide file tree
Showing 47 changed files with 114 additions and 114 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ $(libcppdir)/tokenlist.o: lib/tokenlist.cpp externals/simplecpp/simplecpp.h lib/
$(libcppdir)/utils.o: lib/utils.cpp lib/config.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/utils.cpp

$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp

$(libcppdir)/vfvalue.o: lib/vfvalue.cpp lib/config.h lib/errortypes.h lib/mathlib.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vfvalue.h
Expand Down
2 changes: 1 addition & 1 deletion lib/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CPPCHECKLIB Check {
static std::list<Check *> &instances();

/** run checks, the token list is not simplified */
virtual void runChecks(const Tokenizer *, const Settings *, ErrorLogger *) = 0;
virtual void runChecks(const Tokenizer &, ErrorLogger *) = 0;

/** get error messages */
virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const = 0;
Expand Down
6 changes: 3 additions & 3 deletions lib/check64bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

#include "check.h"
#include "config.h"
#include "tokenize.h"

#include <string>

class ErrorLogger;
class Settings;
class Token;
class Tokenizer;


/// @addtogroup Checks
Expand All @@ -50,8 +50,8 @@ class CPPCHECKLIB Check64BitPortability : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}

/** @brief Run checks against the normal token list */
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
Check64BitPortability check64BitPortability(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
Check64BitPortability check64BitPortability(&tokenizer, tokenizer.getSettings(), errorLogger);
check64BitPortability.pointerassignment();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/checkassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

#include "check.h"
#include "config.h"
#include "tokenize.h"

#include <string>

class ErrorLogger;
class Scope;
class Settings;
class Token;
class Tokenizer;

/// @addtogroup Checks
/// @{
Expand All @@ -48,8 +48,8 @@ class CPPCHECKLIB CheckAssert : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}

/** run checks, the token list is not simplified */
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
CheckAssert checkAssert(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckAssert checkAssert(&tokenizer, tokenizer.getSettings(), errorLogger);
checkAssert.assertWithSideEffects();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/checkautovariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
#include "check.h"
#include "config.h"
#include "errortypes.h"
#include "tokenize.h"

#include <string>
#include <set>

class Settings;
class Token;
class Tokenizer;
class ErrorLogger;
class Variable;

Expand All @@ -54,8 +54,8 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}

/** @brief Run checks against the normal token list */
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
CheckAutoVariables checkAutoVariables(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckAutoVariables checkAutoVariables(&tokenizer, tokenizer.getSettings(), errorLogger);
checkAutoVariables.assignFunctionArg();
checkAutoVariables.checkVarLifetime();
checkAutoVariables.autoVariables();
Expand Down
6 changes: 3 additions & 3 deletions lib/checkbool.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

#include "check.h"
#include "config.h"
#include "tokenize.h"

#include <string>

class ErrorLogger;
class Settings;
class Token;
class Tokenizer;

/// @addtogroup Checks
/// @{
Expand All @@ -48,8 +48,8 @@ class CPPCHECKLIB CheckBool : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}

/** @brief Run checks against the normal token list */
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
CheckBool checkBool(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckBool checkBool(&tokenizer, tokenizer.getSettings(), errorLogger);

// Checks
checkBool.checkComparisonOfBoolExpressionWithInt();
Expand Down
6 changes: 3 additions & 3 deletions lib/checkboost.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ class CPPCHECKLIB CheckBoost : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}

/** @brief Run checks against the normal token list */
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
if (!tokenizer->isCPP())
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
if (!tokenizer.isCPP())
return;

CheckBoost checkBoost(tokenizer, settings, errorLogger);
CheckBoost checkBoost(&tokenizer, tokenizer.getSettings(), errorLogger);
checkBoost.checkBoostForeachModification();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/checkbufferoverrun.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "errortypes.h"
#include "mathlib.h"
#include "symboldatabase.h"
#include "tokenize.h"
#include "vfvalue.h"

#include <list>
Expand All @@ -42,7 +43,6 @@ namespace tinyxml2 {
class ErrorLogger;
class Settings;
class Token;
class Tokenizer;

/// @addtogroup Checks
/// @{
Expand All @@ -66,8 +66,8 @@ class CPPCHECKLIB CheckBufferOverrun : public Check {
CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}

void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
CheckBufferOverrun checkBufferOverrun(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckBufferOverrun checkBufferOverrun(&tokenizer, tokenizer.getSettings(), errorLogger);
checkBufferOverrun.arrayIndex();
checkBufferOverrun.pointerArithmetic();
checkBufferOverrun.bufferOverflow();
Expand Down
6 changes: 3 additions & 3 deletions lib/checkclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class CPPCHECKLIB CheckClass : public Check {
CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger);

/** @brief Run checks on the normal token list */
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
if (tokenizer->isC())
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
if (tokenizer.isC())
return;

CheckClass checkClass(tokenizer, settings, errorLogger);
CheckClass checkClass(&tokenizer, tokenizer.getSettings(), errorLogger);

// can't be a simplified check .. the 'sizeof' is used.
checkClass.checkMemset();
Expand Down
6 changes: 3 additions & 3 deletions lib/checkcondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
#include "config.h"
#include "mathlib.h"
#include "errortypes.h"
#include "tokenize.h"

#include <set>
#include <string>

class Settings;
class Token;
class Tokenizer;
class ErrorLogger;
class ValueType;

Expand All @@ -56,8 +56,8 @@ class CPPCHECKLIB CheckCondition : public Check {
CheckCondition(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}

void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
CheckCondition checkCondition(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckCondition checkCondition(&tokenizer, tokenizer.getSettings(), errorLogger);
checkCondition.multiCondition();
checkCondition.clarifyCondition(); // not simplified because ifAssign
checkCondition.multiCondition2();
Expand Down
6 changes: 3 additions & 3 deletions lib/checkexceptionsafety.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class CPPCHECKLIB CheckExceptionSafety : public Check {
CheckExceptionSafety(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}

void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
if (tokenizer->isC())
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
if (tokenizer.isC())
return;

CheckExceptionSafety checkExceptionSafety(tokenizer, settings, errorLogger);
CheckExceptionSafety checkExceptionSafety(&tokenizer, tokenizer.getSettings(), errorLogger);
checkExceptionSafety.destructors();
checkExceptionSafety.deallocThrow();
checkExceptionSafety.checkRethrowCopy();
Expand Down
6 changes: 3 additions & 3 deletions lib/checkfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
#include "errortypes.h"
#include "library.h"
#include "settings.h"
#include "tokenize.h"

#include <map>
#include <string>
#include <utility>

class Token;
class Tokenizer;
class ErrorLogger;

namespace ValueFlow {
Expand All @@ -58,8 +58,8 @@ class CPPCHECKLIB CheckFunctions : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}

/** @brief Run checks against the normal token list */
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
CheckFunctions checkFunctions(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckFunctions checkFunctions(&tokenizer, tokenizer.getSettings(), errorLogger);

checkFunctions.checkIgnoredReturnValue();
checkFunctions.checkMissingReturn(); // Missing "return" in exit path
Expand Down
8 changes: 4 additions & 4 deletions lib/checkinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
#include "config.h"
#include "errortypes.h"
#include "settings.h"
#include "tokenize.h"

#include <string>

class ErrorLogger;
class Token;
class Tokenizer;

/// @addtogroup Checks
/// @{
Expand All @@ -47,11 +47,11 @@ class CPPCHECKLIB CheckInternal : public Check {
CheckInternal(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}

void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
if (!settings->checks.isEnabled(Checks::internalCheck))
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
if (!tokenizer.getSettings()->checks.isEnabled(Checks::internalCheck))
return;

CheckInternal checkInternal(tokenizer, settings, errorLogger);
CheckInternal checkInternal(&tokenizer, tokenizer.getSettings(), errorLogger);

checkInternal.checkTokenMatchPatterns();
checkInternal.checkTokenSimpleMatchPatterns();
Expand Down
6 changes: 3 additions & 3 deletions lib/checkio.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
#include "check.h"
#include "config.h"
#include "errortypes.h"
#include "tokenize.h"

#include <ostream>
#include <string>

class Function;
class Settings;
class Token;
class Tokenizer;
class Variable;
class ErrorLogger;

Expand All @@ -49,8 +49,8 @@ class CPPCHECKLIB CheckIO : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}

/** @brief Run checks on the normal token list */
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
CheckIO checkIO(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckIO checkIO(&tokenizer, tokenizer.getSettings(), errorLogger);

checkIO.checkWrongPrintfScanfArguments();
checkIO.checkCoutCerrMisusage();
Expand Down
6 changes: 3 additions & 3 deletions lib/checkleakautovar.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "check.h"
#include "config.h"
#include "library.h"
#include "tokenize.h"

#include <map>
#include <set>
Expand All @@ -34,7 +35,6 @@
class ErrorLogger;
class Settings;
class Token;
class Tokenizer;


class CPPCHECKLIB VarInfo {
Expand Down Expand Up @@ -115,8 +115,8 @@ class CPPCHECKLIB CheckLeakAutoVar : public Check {
CheckLeakAutoVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}

void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
CheckLeakAutoVar checkLeakAutoVar(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckLeakAutoVar checkLeakAutoVar(&tokenizer, tokenizer.getSettings(), errorLogger);
checkLeakAutoVar.check();
}

Expand Down
18 changes: 9 additions & 9 deletions lib/checkmemoryleak.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ class CPPCHECKLIB CheckMemoryLeakInFunction : private Check, public CheckMemoryL
CheckMemoryLeakInFunction(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {}

void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
CheckMemoryLeakInFunction checkMemoryLeak(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, tokenizer.getSettings(), errorLogger);
checkMemoryLeak.checkReallocUsage();
}

Expand Down Expand Up @@ -224,11 +224,11 @@ class CPPCHECKLIB CheckMemoryLeakInClass : private Check, private CheckMemoryLea
CheckMemoryLeakInClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {}

void runChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) override {
if (!tokenizr->isCPP())
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
if (!tokenizer.isCPP())
return;

CheckMemoryLeakInClass checkMemoryLeak(tokenizr, settings, errLog);
CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, tokenizer.getSettings(), errorLogger);
checkMemoryLeak.check();
}

Expand Down Expand Up @@ -269,8 +269,8 @@ class CPPCHECKLIB CheckMemoryLeakStructMember : private Check, private CheckMemo
CheckMemoryLeakStructMember(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {}

void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
CheckMemoryLeakStructMember checkMemoryLeak(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckMemoryLeakStructMember checkMemoryLeak(&tokenizer, tokenizer.getSettings(), errorLogger);
checkMemoryLeak.check();
}

Expand Down Expand Up @@ -305,8 +305,8 @@ class CPPCHECKLIB CheckMemoryLeakNoVar : private Check, private CheckMemoryLeak
CheckMemoryLeakNoVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {}

void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
CheckMemoryLeakNoVar checkMemoryLeak(tokenizer, settings, errorLogger);
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckMemoryLeakNoVar checkMemoryLeak(&tokenizer, tokenizer.getSettings(), errorLogger);
checkMemoryLeak.check();
}

Expand Down
Loading

0 comments on commit bfb50ca

Please sign in to comment.