| 
    Cppcheck
    
   | 
 
checks dealing with suspicious usage of boolean type (not for evaluating conditions) More...
#include <checkbool.h>
  
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 | |
| Check & | operator= (const Check &)=delete | 
| const std::string & | name () const | 
| class name, used to generate documentation  More... | |
| virtual FileInfo * | getFileInfo (const Tokenizer &, const Settings &) const | 
| virtual FileInfo * | loadFileInfoFromXml (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 {} | 
checks dealing with suspicious usage of boolean type (not for evaluating conditions)
Definition at line 41 of file checkbool.h.
      
  | 
  inline | 
This constructor is used when registering the CheckClass.
Definition at line 44 of file checkbool.h.
      
  | 
  inlineprivate | 
This constructor is used when running checks.
Definition at line 48 of file checkbool.h.
      
  | 
  private | 
Definition at line 482 of file checkbool.cpp.
References CWE704, normal, Check::reportError(), and style.
Referenced by checkAssignBoolToFloat(), and getErrorMessages().
      
  | 
  private | 
Definition at line 334 of file checkbool.cpp.
References CWE587, error, normal, and Check::reportError().
Referenced by checkAssignBoolToPointer(), and getErrorMessages().
      
  | 
  private | 
Definition at line 136 of file checkbool.cpp.
References CWE398, inconclusive, Check::reportError(), and style.
Referenced by checkBitwiseOnBoolean(), and getErrorMessages().
      
  | 
  private | 
assigning bool to float
Definition at line 465 of file checkbool.cpp.
References assignBoolToFloatError(), astIsBool(), astIsFloat(), Scope::bodyEnd, Scope::bodyStart, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Tokenizer::isCPP(), SimpleEnableGroup< T >::isEnabled(), Check::logChecker(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, and style.
Referenced by runChecks().
      
  | 
  private | 
assigning bool to pointer
Definition at line 321 of file checkbool.cpp.
References assignBoolToPointerError(), astIsBool(), astIsPointer(), Scope::bodyEnd, Scope::bodyStart, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Check::logChecker(), Check::mTokenizer, and Token::next().
Referenced by runChecks().
      
  | 
  private | 
Check for using bool in bitwise expression
Definition at line 91 of file checkbool.cpp.
References astIsBool(), bitwiseOnBooleanError(), Scope::bodyEnd, Scope::bodyStart, Settings::certainty, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), inconclusive, isConstExpression(), isConvertedToBool(), SimpleEnableGroup< T >::isEnabled(), Settings::library, Check::logChecker(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, and style.
Referenced by runChecks().
      
  | 
  private | 
Check for comparing a bool expression with an integer other than 0 or 1
Definition at line 342 of file checkbool.cpp.
References astIsBool(), Token::astOperand1(), Token::astOperand2(), Scope::bodyEnd, Scope::bodyStart, comparisonOfBoolExpressionWithIntError(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Token::getValueGE(), Token::getValueLE(), ValueFlow::Value::intvalue, SimpleEnableGroup< T >::isEnabled(), Token::isName(), Token::isOp(), Settings::isPremiumEnabled(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, and warning.
Referenced by runChecks().
      
  | 
  private | 
Check for comparison of variable of type bool
Definition at line 270 of file checkbool.cpp.
References Scope::bodyEnd, Scope::bodyStart, comparisonOfBoolWithBoolError(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), isBool(), Tokenizer::isCPP(), SimpleEnableGroup< T >::isEnabled(), Check::logChecker(), Check::mSettings, Check::mTokenizer, Token::next(), Token::previous(), Settings::severity, Token::str(), style, Token::variable(), and Token::varId().
Referenced by runChecks().
      
  | 
  private | 
Check for suspicious comparison of a bool and a non-zero (and non-one) value (e.g.
"if (!x==4)")
Definition at line 153 of file checkbool.cpp.
References Token::astOperand1(), Token::astOperand2(), Scope::bodyEnd, Scope::bodyStart, comparisonOfBoolWithInvalidComparator(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Token::isBoolean(), Tokenizer::isCPP(), SimpleEnableGroup< T >::isEnabled(), Check::logChecker(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, Token::str(), Token::varId(), and warning.
Referenced by runChecks().
      
  | 
  private | 
Check for comparison of function returning bool
Definition at line 204 of file checkbool.cpp.
References Token::astOperand1(), Scope::bodyEnd, Scope::bodyStart, comparisonOfFuncReturningBoolError(), comparisonOfTwoFuncsReturningBoolError(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Tokenizer::isCPP(), isCPPCast(), SimpleEnableGroup< T >::isEnabled(), Check::logChecker(), Check::mSettings, Check::mTokenizer, Token::next(), Token::previous(), Settings::severity, Token::simpleMatch(), Token::str(), style, and tokenIsFunctionReturningBool().
Referenced by runChecks().
      
  | 
  private | 
Check for using postfix increment on bool
Definition at line 51 of file checkbool.cpp.
References astIsBool(), Scope::bodyEnd, Scope::bodyStart, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), incrementBooleanError(), SimpleEnableGroup< T >::isEnabled(), Settings::isPremiumEnabled(), Check::logChecker(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, and style.
Referenced by runChecks().
      
  | 
  inlineoverrideprivatevirtual | 
get information about this class, used to generate documentation
Implements Check.
Definition at line 131 of file checkbool.h.
      
  | 
  private | 
Definition at line 402 of file checkbool.cpp.
References CWE398, normal, Check::reportError(), and warning.
Referenced by checkComparisonOfBoolExpressionWithInt(), and getErrorMessages().
      
  | 
  private | 
Definition at line 311 of file checkbool.cpp.
References CWE398, normal, Check::reportError(), and style.
Referenced by checkComparisonOfBoolWithBool(), and getErrorMessages().
      
  | 
  private | 
Definition at line 180 of file checkbool.cpp.
References Check::reportError(), and warning.
Referenced by checkComparisonOfBoolWithInt(), and getErrorMessages().
      
  | 
  private | 
Definition at line 248 of file checkbool.cpp.
References CWE398, normal, Check::reportError(), and style.
Referenced by checkComparisonOfFuncReturningBool(), and getErrorMessages().
      
  | 
  private | 
Definition at line 257 of file checkbool.cpp.
References CWE398, normal, Check::reportError(), and style.
Referenced by checkComparisonOfFuncReturningBool(), and getErrorMessages().
      
  | 
  inlineoverrideprivatevirtual | 
get error messages
Implements Check.
Definition at line 112 of file checkbool.h.
References assignBoolToFloatError(), assignBoolToPointerError(), bitwiseOnBooleanError(), comparisonOfBoolExpressionWithIntError(), comparisonOfBoolWithBoolError(), comparisonOfBoolWithInvalidComparator(), comparisonOfFuncReturningBoolError(), comparisonOfTwoFuncsReturningBoolError(), incrementBooleanError(), pointerArithBoolError(), and returnValueBoolError().
      
  | 
  private | 
Definition at line 68 of file checkbool.cpp.
References CWE398, normal, Check::reportError(), and style.
Referenced by checkIncrementBoolean(), and getErrorMessages().
      
  | 
  inlinestaticprivate | 
Definition at line 127 of file checkbool.h.
      
  | 
  private | 
Check for 'if (p+1)' etc.
either somebody forgot to dereference, or else somebody uses pointer overflow
Definition at line 413 of file checkbool.cpp.
References Token::astOperand1(), Token::astOperand2(), Scope::bodyEnd, Scope::classDef, Scope::eDo, Scope::eFor, Scope::eIf, Token::findsimplematch(), Tokenizer::getSymbolDatabase(), Scope::isLoopScope(), Check::logChecker(), Check::mTokenizer, Token::next(), pointerArithBoolCond(), SymbolDatabase::scopeList, Token::tokAt(), and Scope::type.
Referenced by runChecks().
      
  | 
  private | 
Definition at line 436 of file checkbool.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::isBinaryOp(), Token::Match(), pointerArithBoolError(), and Token::str().
Referenced by pointerArithBool().
      
  | 
  private | 
Definition at line 456 of file checkbool.cpp.
References CWE571, error, normal, and Check::reportError().
Referenced by getErrorMessages(), and pointerArithBoolCond().
      
  | 
  private | 
Definition at line 516 of file checkbool.cpp.
References Check::reportError(), and style.
Referenced by getErrorMessages(), and returnValueOfFunctionReturningBool().
      
  | 
  private | 
Check if a function returning bool returns an integer other than 0 or 1
Definition at line 488 of file checkbool.cpp.
References Scope::bodyEnd, Scope::bodyStart, findLambdaEndToken(), Scope::function, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Function::retDef, returnValueBoolError(), Token::scope(), Settings::severity, Token::simpleMatch(), and style.
Referenced by runChecks().
      
  | 
  inlineoverrideprivatevirtual | 
Run checks against the normal token list.
Implements Check.
Definition at line 52 of file checkbool.h.
References checkAssignBoolToFloat(), checkAssignBoolToPointer(), checkBitwiseOnBoolean(), checkComparisonOfBoolExpressionWithInt(), checkComparisonOfBoolWithBool(), checkComparisonOfBoolWithInt(), checkComparisonOfFuncReturningBool(), checkIncrementBoolean(), Tokenizer::getSettings(), pointerArithBool(), and returnValueOfFunctionReturningBool().