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

Various small checks for automatic variables. More...

#include <checkautovariables.h>

Inheritance diagram for CheckAutoVariables:
Check

Public Member Functions

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

 CheckAutoVariables (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 assignFunctionArg ()
 assign function argument More...
 
void autoVariables ()
 Check auto variables. More...
 
bool checkAutoVariableAssignment (const Token *expr, bool inconclusive, const Token *startToken=nullptr)
 Check variable assignment. More...
 
void checkVarLifetime ()
 
void checkVarLifetimeScope (const Token *start, const Token *end)
 
void errorAutoVariableAssignment (const Token *tok, bool inconclusive)
 
void errorReturnDanglingLifetime (const Token *tok, const ValueFlow::Value *val)
 
void errorInvalidLifetime (const Token *tok, const ValueFlow::Value *val)
 
void errorDanglngLifetime (const Token *tok, const ValueFlow::Value *val)
 
void errorDanglingTemporaryLifetime (const Token *tok, const ValueFlow::Value *val, const Token *tempTok)
 
void errorReturnReference (const Token *tok, ErrorPath errorPath, bool inconclusive)
 
void errorDanglingReference (const Token *tok, const Variable *var, ErrorPath errorPath)
 
void errorDanglingTempReference (const Token *tok, ErrorPath errorPath, bool inconclusive)
 
void errorReturnTempReference (const Token *tok, ErrorPath errorPath, bool inconclusive)
 
void errorInvalidDeallocation (const Token *tok, const ValueFlow::Value *val)
 
void errorUselessAssignmentArg (const Token *tok)
 
void errorUselessAssignmentPtrArg (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...
 
bool diag (const Token *tokvalue)
 returns true if tokvalue has already been diagnosed More...
 

Static Private Member Functions

static std::string myName ()
 

Private Attributes

std::set< const Token * > mDiagDanglingTemp
 

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

Various small checks for automatic variables.

Definition at line 47 of file checkautovariables.h.

Constructor & Destructor Documentation

◆ CheckAutoVariables() [1/2]

CheckAutoVariables::CheckAutoVariables ( )
inline

This constructor is used when registering the CheckClass.

Definition at line 50 of file checkautovariables.h.

◆ CheckAutoVariables() [2/2]

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

This constructor is used when running checks.

Definition at line 54 of file checkautovariables.h.

Member Function Documentation

◆ assignFunctionArg()

void CheckAutoVariables::assignFunctionArg ( )
private

◆ autoVariables()

void CheckAutoVariables::autoVariables ( )
private

◆ checkAutoVariableAssignment()

bool CheckAutoVariables::checkAutoVariableAssignment ( const Token expr,
bool  inconclusive,
const Token startToken = nullptr 
)
private

Check variable assignment.

. value must be changed later or there will be a error reported

Returns
true if error is reported

Definition at line 326 of file checkautovariables.cpp.

References errorAutoVariableAssignment(), Token::findsimplematch(), inconclusive, Token::link(), Token::linkAt(), Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), and Token::str().

Referenced by autoVariables().

◆ checkVarLifetime()

void CheckAutoVariables::checkVarLifetime ( )
private

◆ checkVarLifetimeScope()

void CheckAutoVariables::checkVarLifetimeScope ( const Token start,
const Token end 
)
private

◆ classInfo()

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

get information about this class, used to generate documentation

Implements Check.

Definition at line 113 of file checkautovariables.h.

◆ diag()

bool CheckAutoVariables::diag ( const Token tokvalue)
private

returns true if tokvalue has already been diagnosed

Definition at line 404 of file checkautovariables.cpp.

References mDiagDanglingTemp.

Referenced by checkVarLifetimeScope().

◆ errorAutoVariableAssignment()

void CheckAutoVariables::errorAutoVariableAssignment ( const Token tok,
bool  inconclusive 
)
private

◆ errorDanglingReference()

void CheckAutoVariables::errorDanglingReference ( const Token tok,
const Variable var,
ErrorPath  errorPath 
)
private

◆ errorDanglingTemporaryLifetime()

void CheckAutoVariables::errorDanglingTemporaryLifetime ( const Token tok,
const ValueFlow::Value val,
const Token tempTok 
)
private

◆ errorDanglingTempReference()

void CheckAutoVariables::errorDanglingTempReference ( const Token tok,
ErrorPath  errorPath,
bool  inconclusive 
)
private

Definition at line 734 of file checkautovariables.cpp.

References CWE562, error, inconclusive, normal, and Check::reportError().

Referenced by checkVarLifetimeScope(), and getErrorMessages().

◆ errorDanglngLifetime()

void CheckAutoVariables::errorDanglngLifetime ( const Token tok,
const ValueFlow::Value val 
)
private

◆ errorInvalidDeallocation()

void CheckAutoVariables::errorInvalidDeallocation ( const Token tok,
const ValueFlow::Value val 
)
private

◆ errorInvalidLifetime()

void CheckAutoVariables::errorInvalidLifetime ( const Token tok,
const ValueFlow::Value val 
)
private

◆ errorReturnDanglingLifetime()

void CheckAutoVariables::errorReturnDanglingLifetime ( const Token tok,
const ValueFlow::Value val 
)
private

◆ errorReturnReference()

void CheckAutoVariables::errorReturnReference ( const Token tok,
ErrorPath  errorPath,
bool  inconclusive 
)
private

Definition at line 741 of file checkautovariables.cpp.

References CWE562, error, inconclusive, normal, and Check::reportError().

Referenced by checkVarLifetimeScope(), and getErrorMessages().

◆ errorReturnTempReference()

void CheckAutoVariables::errorReturnTempReference ( const Token tok,
ErrorPath  errorPath,
bool  inconclusive 
)
private

Definition at line 757 of file checkautovariables.cpp.

References CWE562, error, inconclusive, normal, and Check::reportError().

Referenced by checkVarLifetimeScope(), and getErrorMessages().

◆ errorUselessAssignmentArg()

void CheckAutoVariables::errorUselessAssignmentArg ( const Token tok)
private

Definition at line 388 of file checkautovariables.cpp.

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

Referenced by assignFunctionArg(), and getErrorMessages().

◆ errorUselessAssignmentPtrArg()

void CheckAutoVariables::errorUselessAssignmentPtrArg ( const Token tok)
private

Definition at line 396 of file checkautovariables.cpp.

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

Referenced by assignFunctionArg(), and getErrorMessages().

◆ getErrorMessages()

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

◆ myName()

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

Definition at line 109 of file checkautovariables.h.

◆ runChecks()

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

Run checks against the normal token list.

Implements Check.

Definition at line 58 of file checkautovariables.h.

References assignFunctionArg(), autoVariables(), checkVarLifetime(), and Tokenizer::getSettings().

Member Data Documentation

◆ mDiagDanglingTemp

std::set<const Token*> CheckAutoVariables::mDiagDanglingTemp
private

Definition at line 127 of file checkautovariables.h.

Referenced by diag().


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