Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ validateRules:

###### Build

$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.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/vf_analyzers.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.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/vf_analyzers.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp

$(libcppdir)/tokenize.o: lib/tokenize.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/astutils.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/summaries.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/vfvalue.h
Expand All @@ -463,7 +463,7 @@ $(libcppdir)/addoninfo.o: lib/addoninfo.cpp externals/picojson/picojson.h lib/ad
$(libcppdir)/analyzerinfo.o: lib/analyzerinfo.cpp externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/mathlib.h lib/path.h lib/platform.h lib/standards.h lib/utils.h lib/xml.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/analyzerinfo.cpp

$(libcppdir)/astutils.o: lib/astutils.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checkclass.h lib/config.h lib/errortypes.h lib/findtoken.h lib/infer.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
$(libcppdir)/astutils.o: lib/astutils.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checkclass.h lib/config.h lib/errortypes.h lib/findtoken.h lib/infer.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/astutils.cpp

$(libcppdir)/check.o: lib/check.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
Expand Down Expand Up @@ -718,7 +718,7 @@ test/testbool.o: test/testbool.cpp externals/simplecpp/simplecpp.h lib/addoninfo
test/testboost.o: test/testboost.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkboost.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testboost.cpp

test/testbufferoverrun.o: test/testbufferoverrun.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkbufferoverrun.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
test/testbufferoverrun.o: test/testbufferoverrun.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkbufferoverrun.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testbufferoverrun.cpp

test/testcharvar.o: test/testcharvar.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkother.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
Expand Down Expand Up @@ -844,7 +844,7 @@ test/testsizeof.o: test/testsizeof.cpp externals/simplecpp/simplecpp.h lib/addon
test/teststandards.o: test/teststandards.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/teststandards.cpp

test/teststl.o: test/teststl.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkstl.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
test/teststl.o: test/teststl.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkstl.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/teststl.cpp

test/teststring.o: test/teststring.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkstring.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
Expand Down Expand Up @@ -877,7 +877,7 @@ test/testtokenlist.o: test/testtokenlist.cpp externals/simplecpp/simplecpp.h lib
test/testtokenrange.o: test/testtokenrange.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/tokenrange.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testtokenrange.cpp

test/testtype.o: test/testtype.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checktype.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
test/testtype.o: test/testtype.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checktype.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testtype.cpp

test/testuninitvar.o: test/testuninitvar.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
Expand Down
15 changes: 15 additions & 0 deletions lib/check64bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,18 @@ void Check64BitPortability::returnIntegerError(const Token *tok)
"and Linux they are of different width. In worst case you end up casting 64-bit integer down to 32-bit pointer. "
"The safe way is to always return a pointer.", CWE758, Certainty::normal);
}

void Check64BitPortability::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
{
Check64BitPortability check64BitPortability(&tokenizer, &tokenizer.getSettings(), errorLogger);
check64BitPortability.pointerassignment();
}

void Check64BitPortability::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
{
Check64BitPortability c(nullptr, settings, errorLogger);
c.assignmentAddressToIntegerError(nullptr);
c.assignmentIntegerToAddressError(nullptr);
c.returnIntegerError(nullptr);
c.returnPointerError(nullptr);
}
16 changes: 3 additions & 13 deletions lib/check64bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +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 @@ -53,10 +52,7 @@ class CPPCHECKLIB Check64BitPortability : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}

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

/** Check for pointer assignment */
void pointerassignment();
Expand All @@ -66,13 +62,7 @@ class CPPCHECKLIB Check64BitPortability : public Check {
void returnIntegerError(const Token *tok);
void returnPointerError(const Token *tok);

void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
Check64BitPortability c(nullptr, settings, errorLogger);
c.assignmentAddressToIntegerError(nullptr);
c.assignmentIntegerToAddressError(nullptr);
c.returnIntegerError(nullptr);
c.returnPointerError(nullptr);
}
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override;

static std::string myName() {
return "64-bit portability";
Expand Down
13 changes: 13 additions & 0 deletions lib/checkassert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,16 @@ bool CheckAssert::inSameScope(const Token* returnTok, const Token* assignTok)
// TODO: even if a return is in the same scope, the assignment might not affect it.
return returnTok->scope() == assignTok->scope();
}

void CheckAssert::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
{
CheckAssert checkAssert(&tokenizer, &tokenizer.getSettings(), errorLogger);
checkAssert.assertWithSideEffects();
}

void CheckAssert::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
{
CheckAssert c(nullptr, settings, errorLogger);
c.sideEffectInAssertError(nullptr, "function");
c.assignmentInAssertError(nullptr, "var");
}
13 changes: 3 additions & 10 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 @@ -49,10 +49,7 @@ class CPPCHECKLIB CheckAssert : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}

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

void assertWithSideEffects();

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

void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
CheckAssert c(nullptr, settings, errorLogger);
c.sideEffectInAssertError(nullptr, "function");
c.assignmentInAssertError(nullptr, "var");
}
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override;

static std::string myName() {
return "Assert";
Expand Down
25 changes: 25 additions & 0 deletions lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,3 +787,28 @@ void CheckAutoVariables::errorInvalidDeallocation(const Token *tok, const ValueF
"The deallocation of " + type + " results in undefined behaviour. You should only free memory "
"that has been allocated dynamically.", CWE590, Certainty::normal);
}

void CheckAutoVariables::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
{
CheckAutoVariables checkAutoVariables(&tokenizer, &tokenizer.getSettings(), errorLogger);
checkAutoVariables.assignFunctionArg();
checkAutoVariables.checkVarLifetime();
checkAutoVariables.autoVariables();
}

void CheckAutoVariables::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
{
CheckAutoVariables c(nullptr,settings,errorLogger);
c.errorAutoVariableAssignment(nullptr, false);
c.errorReturnReference(nullptr, ErrorPath{}, false);
c.errorDanglingReference(nullptr, nullptr, ErrorPath{});
c.errorReturnTempReference(nullptr, ErrorPath{}, false);
c.errorDanglingTempReference(nullptr, ErrorPath{}, false);
c.errorInvalidDeallocation(nullptr, nullptr);
c.errorUselessAssignmentArg(nullptr);
c.errorUselessAssignmentPtrArg(nullptr);
c.errorReturnDanglingLifetime(nullptr, nullptr);
c.errorInvalidLifetime(nullptr, nullptr);
c.errorDanglngLifetime(nullptr, nullptr);
c.errorDanglingTemporaryLifetime(nullptr, nullptr, nullptr);
}
25 changes: 3 additions & 22 deletions lib/checkautovariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "check.h"
#include "config.h"
#include "errortypes.h"
#include "tokenize.h"

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

namespace ValueFlow {
class Value;
Expand All @@ -55,12 +55,7 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}

/** @brief Run checks against the normal token list */
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
CheckAutoVariables checkAutoVariables(&tokenizer, &tokenizer.getSettings(), errorLogger);
checkAutoVariables.assignFunctionArg();
checkAutoVariables.checkVarLifetime();
checkAutoVariables.autoVariables();
}
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override;

/** assign function argument */
void assignFunctionArg();
Expand Down Expand Up @@ -90,21 +85,7 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
void errorUselessAssignmentArg(const Token *tok);
void errorUselessAssignmentPtrArg(const Token *tok);

void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
CheckAutoVariables c(nullptr,settings,errorLogger);
c.errorAutoVariableAssignment(nullptr, false);
c.errorReturnReference(nullptr, ErrorPath{}, false);
c.errorDanglingReference(nullptr, nullptr, ErrorPath{});
c.errorReturnTempReference(nullptr, ErrorPath{}, false);
c.errorDanglingTempReference(nullptr, ErrorPath{}, false);
c.errorInvalidDeallocation(nullptr, nullptr);
c.errorUselessAssignmentArg(nullptr);
c.errorUselessAssignmentPtrArg(nullptr);
c.errorReturnDanglingLifetime(nullptr, nullptr);
c.errorInvalidLifetime(nullptr, nullptr);
c.errorDanglngLifetime(nullptr, nullptr);
c.errorDanglingTemporaryLifetime(nullptr, nullptr, nullptr);
}
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override;

static std::string myName() {
return "Auto Variables";
Expand Down
33 changes: 33 additions & 0 deletions lib/checkbool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,36 @@ void CheckBool::returnValueBoolError(const Token *tok)
{
reportError(tok, Severity::style, "returnNonBoolInBooleanFunction", "Non-boolean value returned from function returning bool");
}

void CheckBool::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
{
CheckBool checkBool(&tokenizer, &tokenizer.getSettings(), errorLogger);

// Checks
checkBool.checkComparisonOfBoolExpressionWithInt();
checkBool.checkComparisonOfBoolWithInt();
checkBool.checkAssignBoolToFloat();
checkBool.pointerArithBool();
checkBool.returnValueOfFunctionReturningBool();
checkBool.checkComparisonOfFuncReturningBool();
checkBool.checkComparisonOfBoolWithBool();
checkBool.checkIncrementBoolean();
checkBool.checkAssignBoolToPointer();
checkBool.checkBitwiseOnBoolean();
}

void CheckBool::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
{
CheckBool c(nullptr, settings, errorLogger);
c.assignBoolToPointerError(nullptr);
c.assignBoolToFloatError(nullptr);
c.comparisonOfFuncReturningBoolError(nullptr, "func_name");
c.comparisonOfTwoFuncsReturningBoolError(nullptr, "func_name1", "func_name2");
c.comparisonOfBoolWithBoolError(nullptr, "var_name");
c.incrementBooleanError(nullptr);
c.bitwiseOnBooleanError(nullptr, "expression", "&&");
c.comparisonOfBoolExpressionWithIntError(nullptr, true);
c.pointerArithBoolError(nullptr);
c.comparisonOfBoolWithInvalidComparator(nullptr, "expression");
c.returnValueBoolError(nullptr);
}
Loading