Cppcheck
Public Member Functions | Private Member Functions | Static Private Member Functions | List of all members
CheckBool Class Reference

checks dealing with suspicious usage of boolean type (not for evaluating conditions) More...

#include <checkbool.h>

Inheritance diagram for CheckBool:
Check

Public Member Functions

 CheckBool ()
 This constructor is used when registering the CheckClass. More...
 
- Public Member Functions inherited from Check
 Check (const std::string &aname)
 This constructor is used when registering the CheckClass. More...
 
virtual ~Check ()
 
 Check (const Check &)=delete
 
Checkoperator= (const Check &)=delete
 
const std::string & name () const
 class name, used to generate documentation More...
 
virtual FileInfogetFileInfo (const Tokenizer &, const Settings &) const
 
virtual FileInfoloadFileInfoFromXml (const tinyxml2::XMLElement *xmlElement) const
 
virtual bool analyseWholeProgram (const CTU::FileInfo *ctu, const std::list< FileInfo * > &fileInfo, const Settings &, ErrorLogger &)
 

Private Member Functions

 CheckBool (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
 This constructor is used when running checks. More...
 
void runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger) override
 Run checks against the normal token list. More...
 
void checkComparisonOfFuncReturningBool ()
 Check for comparison of function returning bool More...
 
void checkComparisonOfBoolWithBool ()
 Check for comparison of variable of type bool More...
 
void checkIncrementBoolean ()
 Check for using postfix increment on bool More...
 
void checkComparisonOfBoolWithInt ()
 Check for suspicious comparison of a bool and a non-zero (and non-one) value (e.g. More...
 
void checkAssignBoolToPointer ()
 assigning bool to pointer More...
 
void checkAssignBoolToFloat ()
 assigning bool to float More...
 
void checkBitwiseOnBoolean ()
 Check for using bool in bitwise expression More...
 
void checkComparisonOfBoolExpressionWithInt ()
 Check for comparing a bool expression with an integer other than 0 or 1 More...
 
void pointerArithBool ()
 Check for 'if (p+1)' etc. More...
 
void pointerArithBoolCond (const Token *tok)
 
void returnValueOfFunctionReturningBool ()
 Check if a function returning bool returns an integer other than 0 or 1 More...
 
void comparisonOfFuncReturningBoolError (const Token *tok, const std::string &expression)
 
void comparisonOfTwoFuncsReturningBoolError (const Token *tok, const std::string &expression1, const std::string &expression2)
 
void comparisonOfBoolWithBoolError (const Token *tok, const std::string &expression)
 
void incrementBooleanError (const Token *tok)
 
void comparisonOfBoolWithInvalidComparator (const Token *tok, const std::string &expression)
 
void assignBoolToPointerError (const Token *tok)
 
void assignBoolToFloatError (const Token *tok)
 
void bitwiseOnBooleanError (const Token *tok, const std::string &expression, const std::string &op, bool isCompound=false)
 
void comparisonOfBoolExpressionWithIntError (const Token *tok, bool not0or1)
 
void pointerArithBoolError (const Token *tok)
 
void returnValueBoolError (const Token *tok)
 
void getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const override
 get error messages More...
 
std::string classInfo () const override
 get information about this class, used to generate documentation More...
 

Static Private Member Functions

static std::string myName ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Check
static std::list< Check * > & instances ()
 List of registered check classes. More...
 
static void writeToErrorList (const ErrorMessage &errmsg)
 Write given error to stdout in xml format. More...
 
- Protected Member Functions inherited from Check
 Check (std::string aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
 This constructor is used when running checks. More...
 
void reportError (const Token *tok, const Severity severity, const std::string &id, const std::string &msg)
 report an error More...
 
void reportError (const Token *tok, const Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty)
 report an error More...
 
void reportError (const std::list< const Token * > &callstack, Severity severity, const std::string &id, const std::string &msg)
 report an error More...
 
void reportError (const std::list< const Token * > &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty)
 report an error More...
 
void reportError (const ErrorPath &errorPath, Severity severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
 
void logChecker (const char id[])
 log checker More...
 
ErrorPath getErrorPath (const Token *errtok, const ValueFlow::Value *value, std::string bug) const
 
bool wrongData (const Token *tok, const char *str)
 Use WRONG_DATA in checkers when you check for wrong data. More...
 
- Static Protected Member Functions inherited from Check
static std::string getMessageId (const ValueFlow::Value &value, const char id[])
 
- Protected Attributes inherited from Check
const Tokenizer *const mTokenizer {}
 
const Settings *const mSettings {}
 
ErrorLogger *const mErrorLogger {}
 

Detailed Description

checks dealing with suspicious usage of boolean type (not for evaluating conditions)

Definition at line 41 of file checkbool.h.

Constructor & Destructor Documentation

◆ CheckBool() [1/2]

CheckBool::CheckBool ( )
inline

This constructor is used when registering the CheckClass.

Definition at line 44 of file checkbool.h.

◆ CheckBool() [2/2]

CheckBool::CheckBool ( const Tokenizer tokenizer,
const Settings settings,
ErrorLogger errorLogger 
)
inlineprivate

This constructor is used when running checks.

Definition at line 48 of file checkbool.h.

Member Function Documentation

◆ assignBoolToFloatError()

void CheckBool::assignBoolToFloatError ( const Token tok)
private

Definition at line 482 of file checkbool.cpp.

References CWE704, normal, Check::reportError(), and style.

Referenced by checkAssignBoolToFloat(), and getErrorMessages().

◆ assignBoolToPointerError()

void CheckBool::assignBoolToPointerError ( const Token tok)
private

Definition at line 334 of file checkbool.cpp.

References CWE587, error, normal, and Check::reportError().

Referenced by checkAssignBoolToPointer(), and getErrorMessages().

◆ bitwiseOnBooleanError()

void CheckBool::bitwiseOnBooleanError ( const Token tok,
const std::string &  expression,
const std::string &  op,
bool  isCompound = false 
)
private

Definition at line 136 of file checkbool.cpp.

References CWE398, inconclusive, Check::reportError(), and style.

Referenced by checkBitwiseOnBoolean(), and getErrorMessages().

◆ checkAssignBoolToFloat()

void CheckBool::checkAssignBoolToFloat ( )
private

◆ checkAssignBoolToPointer()

void CheckBool::checkAssignBoolToPointer ( )
private

◆ checkBitwiseOnBoolean()

void CheckBool::checkBitwiseOnBoolean ( )
private

◆ checkComparisonOfBoolExpressionWithInt()

void CheckBool::checkComparisonOfBoolExpressionWithInt ( )
private

◆ checkComparisonOfBoolWithBool()

void CheckBool::checkComparisonOfBoolWithBool ( )
private

◆ checkComparisonOfBoolWithInt()

void CheckBool::checkComparisonOfBoolWithInt ( )
private

◆ checkComparisonOfFuncReturningBool()

void CheckBool::checkComparisonOfFuncReturningBool ( )
private

◆ checkIncrementBoolean()

void CheckBool::checkIncrementBoolean ( )
private

◆ classInfo()

std::string CheckBool::classInfo ( ) const
inlineoverrideprivatevirtual

get information about this class, used to generate documentation

Implements Check.

Definition at line 131 of file checkbool.h.

◆ comparisonOfBoolExpressionWithIntError()

void CheckBool::comparisonOfBoolExpressionWithIntError ( const Token tok,
bool  not0or1 
)
private

Definition at line 402 of file checkbool.cpp.

References CWE398, normal, Check::reportError(), and warning.

Referenced by checkComparisonOfBoolExpressionWithInt(), and getErrorMessages().

◆ comparisonOfBoolWithBoolError()

void CheckBool::comparisonOfBoolWithBoolError ( const Token tok,
const std::string &  expression 
)
private

Definition at line 311 of file checkbool.cpp.

References CWE398, normal, Check::reportError(), and style.

Referenced by checkComparisonOfBoolWithBool(), and getErrorMessages().

◆ comparisonOfBoolWithInvalidComparator()

void CheckBool::comparisonOfBoolWithInvalidComparator ( const Token tok,
const std::string &  expression 
)
private

Definition at line 180 of file checkbool.cpp.

References Check::reportError(), and warning.

Referenced by checkComparisonOfBoolWithInt(), and getErrorMessages().

◆ comparisonOfFuncReturningBoolError()

void CheckBool::comparisonOfFuncReturningBoolError ( const Token tok,
const std::string &  expression 
)
private

Definition at line 248 of file checkbool.cpp.

References CWE398, normal, Check::reportError(), and style.

Referenced by checkComparisonOfFuncReturningBool(), and getErrorMessages().

◆ comparisonOfTwoFuncsReturningBoolError()

void CheckBool::comparisonOfTwoFuncsReturningBoolError ( const Token tok,
const std::string &  expression1,
const std::string &  expression2 
)
private

Definition at line 257 of file checkbool.cpp.

References CWE398, normal, Check::reportError(), and style.

Referenced by checkComparisonOfFuncReturningBool(), and getErrorMessages().

◆ getErrorMessages()

void CheckBool::getErrorMessages ( ErrorLogger errorLogger,
const Settings settings 
) const
inlineoverrideprivatevirtual

◆ incrementBooleanError()

void CheckBool::incrementBooleanError ( const Token tok)
private

Definition at line 68 of file checkbool.cpp.

References CWE398, normal, Check::reportError(), and style.

Referenced by checkIncrementBoolean(), and getErrorMessages().

◆ myName()

static std::string CheckBool::myName ( )
inlinestaticprivate

Definition at line 127 of file checkbool.h.

◆ pointerArithBool()

void CheckBool::pointerArithBool ( )
private

◆ pointerArithBoolCond()

void CheckBool::pointerArithBoolCond ( const Token tok)
private

◆ pointerArithBoolError()

void CheckBool::pointerArithBoolError ( const Token tok)
private

Definition at line 456 of file checkbool.cpp.

References CWE571, error, normal, and Check::reportError().

Referenced by getErrorMessages(), and pointerArithBoolCond().

◆ returnValueBoolError()

void CheckBool::returnValueBoolError ( const Token tok)
private

Definition at line 516 of file checkbool.cpp.

References Check::reportError(), and style.

Referenced by getErrorMessages(), and returnValueOfFunctionReturningBool().

◆ returnValueOfFunctionReturningBool()

void CheckBool::returnValueOfFunctionReturningBool ( )
private

◆ runChecks()

void CheckBool::runChecks ( const Tokenizer tokenizer,
ErrorLogger errorLogger 
)
inlineoverrideprivatevirtual

The documentation for this class was generated from the following files: