Cppcheck
|
Various small checks for automatic variables. More...
#include <checkautovariables.h>
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 | |
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 | |
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 {} |
Various small checks for automatic variables.
Definition at line 47 of file checkautovariables.h.
|
inline |
This constructor is used when registering the CheckClass.
Definition at line 50 of file checkautovariables.h.
|
inlineprivate |
This constructor is used when running checks.
Definition at line 54 of file checkautovariables.h.
|
private |
assign function argument
Definition at line 209 of file checkautovariables.cpp.
References Token::astOperand1(), Scope::bodyEnd, Scope::bodyStart, Token::eIncDecOp, errorUselessAssignmentArg(), errorUselessAssignmentPtrArg(), Token::findsimplematch(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), isNonReferenceArg(), Settings::isPremiumEnabled(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, style, Token::variable(), variableIsUsedInScope(), Token::varId(), and warning.
Referenced by runChecks().
|
private |
Check auto variables.
Definition at line 264 of file checkautovariables.cpp.
References ValueFlow::Value::Address, Scope::bodyEnd, Scope::bodyStart, Settings::certainty, checkAutoVariableAssignment(), errorAutoVariableAssignment(), errorInvalidDeallocation(), Token::eString, findLambdaEndToken(), Token::findmatch(), SymbolDatabase::functionScopes, Library::getDeallocFuncInfo(), Tokenizer::getSymbolDatabase(), hasOverloadedAssignment(), inconclusive, isArrayArg(), isArrayVar(), isAutoVar(), isAutoVariableRHS(), SimpleEnableGroup< T >::isEnabled(), isPtrArg(), isRefPtrArg(), Settings::library, Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::simpleMatch(), and Token::tokAt().
Referenced by runChecks().
|
private |
Check variable assignment.
. value must be changed later or there will be a error 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().
|
private |
Definition at line 680 of file checkautovariables.cpp.
References Scope::bodyEnd, Scope::bodyStart, checkVarLifetimeScope(), Scope::function, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Check::logChecker(), and Check::mTokenizer.
Referenced by runChecks().
Definition at line 541 of file checkautovariables.cpp.
References astIsContainerView(), astIsRHS(), Token::astParent(), Scope::bodyStart, Settings::certainty, Variable::declarationId(), diag(), Scope::eClass, errorDanglingReference(), errorDanglingTemporaryLifetime(), errorDanglingTempReference(), errorDanglngLifetime(), errorInvalidLifetime(), errorReturnDanglingLifetime(), errorReturnReference(), errorReturnTempReference(), Scope::eStruct, Scope::eUnion, Token::exprId(), findLambdaEndToken(), Scope::function, ValueFlow::getLifetimeTokens(), ValueFlow::getLifetimeVariable(), getParentLifetime(), getParentVar(), getPointerDepth(), inconclusive, Variable::isArgument(), isAssignedToNonLocal(), isDanglingSubFunction(), isDeadScope(), isDeadTemporary(), SimpleEnableGroup< T >::isEnabled(), isEscapedReference(), Variable::isGlobal(), isInScope(), ValueFlow::isLifetimeBorrowed(), Variable::isLocal(), Variable::isReference(), Variable::isRValueReference(), Variable::isStatic(), isVariableChanged(), Settings::library, Token::link(), Token::Match(), Check::mSettings, Variable::nameToken(), Token::next(), nextAfterAstRightmostLeaf(), Function::returnsReference(), Function::returnsStandardType(), Token::scope(), Token::simpleMatch(), and Token::variable().
Referenced by checkVarLifetime().
|
inlineoverrideprivatevirtual |
get information about this class, used to generate documentation
Implements Check.
Definition at line 113 of file checkautovariables.h.
|
private |
returns true if tokvalue has already been diagnosed
Definition at line 404 of file checkautovariables.cpp.
References mDiagDanglingTemp.
Referenced by checkVarLifetimeScope().
|
private |
Definition at line 367 of file checkautovariables.cpp.
References CWE562, error, inconclusive, normal, and Check::reportError().
Referenced by autoVariables(), checkAutoVariableAssignment(), and getErrorMessages().
|
private |
Definition at line 748 of file checkautovariables.cpp.
References CWE562, error, Variable::name(), normal, Check::reportError(), and Token::str().
Referenced by checkVarLifetimeScope(), and getErrorMessages().
|
private |
Definition at line 709 of file checkautovariables.cpp.
References CWE562, error, ValueFlow::Value::errorPath, inconclusive, ValueFlow::Value::isInconclusive(), ValueFlow::lifetimeMessage(), normal, and Check::reportError().
Referenced by checkVarLifetimeScope(), and getErrorMessages().
|
private |
Definition at line 734 of file checkautovariables.cpp.
References CWE562, error, inconclusive, normal, and Check::reportError().
Referenced by checkVarLifetimeScope(), and getErrorMessages().
|
private |
Definition at line 724 of file checkautovariables.cpp.
References CWE562, error, ValueFlow::Value::errorPath, Token::expressionString(), inconclusive, ValueFlow::Value::isInconclusive(), ValueFlow::lifetimeMessage(), normal, and Check::reportError().
Referenced by checkVarLifetimeScope(), and getErrorMessages().
|
private |
Definition at line 764 of file checkautovariables.cpp.
References CWE590, error, Token::eString, Check::getErrorPath(), Variable::isGlobal(), Variable::isStatic(), normal, Check::reportError(), Token::str(), Token::tokType(), ValueFlow::Value::tokvalue, and Token::variable().
Referenced by autoVariables(), and getErrorMessages().
|
private |
Definition at line 700 of file checkautovariables.cpp.
References CWE562, error, ValueFlow::Value::errorPath, inconclusive, ValueFlow::Value::isInconclusive(), ValueFlow::lifetimeMessage(), normal, and Check::reportError().
Referenced by checkVarLifetimeScope(), and getErrorMessages().
|
private |
Definition at line 691 of file checkautovariables.cpp.
References CWE562, error, ValueFlow::Value::errorPath, inconclusive, ValueFlow::Value::isInconclusive(), ValueFlow::lifetimeMessage(), normal, and Check::reportError().
Referenced by checkVarLifetimeScope(), and getErrorMessages().
|
private |
Definition at line 741 of file checkautovariables.cpp.
References CWE562, error, inconclusive, normal, and Check::reportError().
Referenced by checkVarLifetimeScope(), and getErrorMessages().
|
private |
Definition at line 757 of file checkautovariables.cpp.
References CWE562, error, inconclusive, normal, and Check::reportError().
Referenced by checkVarLifetimeScope(), and getErrorMessages().
|
private |
Definition at line 388 of file checkautovariables.cpp.
References CWE398, normal, Check::reportError(), and style.
Referenced by assignFunctionArg(), and getErrorMessages().
|
private |
Definition at line 396 of file checkautovariables.cpp.
References CWE398, normal, Check::reportError(), and warning.
Referenced by assignFunctionArg(), and getErrorMessages().
|
inlineoverrideprivatevirtual |
get error messages
Implements Check.
Definition at line 93 of file checkautovariables.h.
References errorAutoVariableAssignment(), errorDanglingReference(), errorDanglingTemporaryLifetime(), errorDanglingTempReference(), errorDanglngLifetime(), errorInvalidDeallocation(), errorInvalidLifetime(), errorReturnDanglingLifetime(), errorReturnReference(), errorReturnTempReference(), errorUselessAssignmentArg(), and errorUselessAssignmentPtrArg().
|
inlinestaticprivate |
Definition at line 109 of file checkautovariables.h.
|
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().
|
private |
Definition at line 127 of file checkautovariables.h.
Referenced by diag().