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

Checking for side effects in assert statements. More...

#include <checkassert.h>

Inheritance diagram for CheckAssert:
Check

Public Member Functions

 CheckAssert ()
 
- 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

 CheckAssert (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
 
void runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger) override
 run checks, the token list is not simplified More...
 
void assertWithSideEffects ()
 
void checkVariableAssignment (const Token *assignTok, const Scope *assertionScope)
 
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
 get error messages More...
 
std::string classInfo () const override
 get information about this class, used to generate documentation More...
 

Static Private Member Functions

static bool inSameScope (const Token *returnTok, const Token *assignTok)
 
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

Checking for side effects in assert statements.

Definition at line 43 of file checkassert.h.

Constructor & Destructor Documentation

◆ CheckAssert() [1/2]

CheckAssert::CheckAssert ( )
inline

Definition at line 45 of file checkassert.h.

◆ CheckAssert() [2/2]

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

Definition at line 48 of file checkassert.h.

Member Function Documentation

◆ assertWithSideEffects()

void CheckAssert::assertWithSideEffects ( )
private

◆ assignmentInAssertError()

void CheckAssert::assignmentInAssertError ( const Token tok,
const std::string &  varname 
)
private

Definition at line 133 of file checkassert.cpp.

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

Referenced by checkVariableAssignment(), and getErrorMessages().

◆ checkVariableAssignment()

void CheckAssert::checkVariableAssignment ( const Token assignTok,
const Scope assertionScope 
)
private

◆ classInfo()

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

get information about this class, used to generate documentation

Implements Check.

Definition at line 75 of file checkassert.h.

◆ getErrorMessages()

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

get error messages

Implements Check.

Definition at line 65 of file checkassert.h.

References assignmentInAssertError(), and sideEffectInAssertError().

◆ inSameScope()

bool CheckAssert::inSameScope ( const Token returnTok,
const Token assignTok 
)
staticprivate

Definition at line 174 of file checkassert.cpp.

References Token::scope().

Referenced by assertWithSideEffects().

◆ myName()

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

Definition at line 71 of file checkassert.h.

◆ runChecks()

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

run checks, the token list is not simplified

Implements Check.

Definition at line 52 of file checkassert.h.

References assertWithSideEffects(), and Tokenizer::getSettings().

◆ sideEffectInAssertError()

void CheckAssert::sideEffectInAssertError ( const Token tok,
const std::string &  functionName 
)
private

Definition at line 121 of file checkassert.cpp.

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

Referenced by assertWithSideEffects(), and getErrorMessages().


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