Cppcheck
|
Check exception safety (exceptions shouldn't cause leaks nor corrupt data) More...
#include <checkexceptionsafety.h>
Public Member Functions | |
CheckExceptionSafety () | |
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 | |
CheckExceptionSafety (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, the token list is not simplified More... | |
void | destructors () |
Don't throw exceptions in destructors. More... | |
void | deallocThrow () |
deallocating memory and then throw (dead pointer) More... | |
void | checkRethrowCopy () |
Don't rethrow a copy of the caught exception; use a bare throw instead. More... | |
void | checkCatchExceptionByValue () |
Check for exceptions that are caught by value instead of by reference More... | |
void | nothrowThrows () |
Check for functions that throw that shouldn't More... | |
void | unhandledExceptionSpecification () |
Check for unhandled exception specification More... | |
void | rethrowNoCurrentException () |
Check for rethrow not from catch scope More... | |
void | destructorsError (const Token *const tok, const std::string &className) |
Don't throw exceptions in destructors. More... | |
void | deallocThrowError (const Token *const tok, const std::string &varname) |
void | rethrowCopyError (const Token *const tok, const std::string &varname) |
void | catchExceptionByValueError (const Token *tok) |
void | noexceptThrowError (const Token *const tok) |
void | unhandledExceptionSpecificationError (const Token *const tok1, const Token *const tok2, const std::string &funcname) |
Missing exception specification. More... | |
void | rethrowNoCurrentExceptionError (const Token *tok) |
Rethrow without currently handled exception. More... | |
void | getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const override |
Generate all possible errors (for –errorlist) More... | |
std::string | classInfo () const override |
wiki formatted description of the class (for –doc) More... | |
Static Private Member Functions | |
static std::string | myName () |
Short description of class (for –doc) More... | |
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 {} |
Check exception safety (exceptions shouldn't cause leaks nor corrupt data)
The problem with these checks is that Cppcheck can't determine what the valid values are for variables. But in some cases (dead pointers) it can be determined that certain variable values are corrupt.
Definition at line 47 of file checkexceptionsafety.h.
|
inline |
This constructor is used when registering the CheckClass.
Definition at line 50 of file checkexceptionsafety.h.
|
inlineprivate |
This constructor is used when running checks.
Definition at line 54 of file checkexceptionsafety.h.
|
private |
Definition at line 235 of file checkexceptionsafety.cpp.
References CWE398, normal, Check::reportError(), and style.
Referenced by checkCatchExceptionByValue(), and getErrorMessages().
|
private |
Check for exceptions that are caught by value instead of by reference
Definition at line 214 of file checkexceptionsafety.cpp.
References Scope::bodyStart, catchExceptionByValueError(), Scope::classDef, Scope::eCatch, Tokenizer::getSymbolDatabase(), Variable::isClass(), SimpleEnableGroup< T >::isEnabled(), Variable::isPointer(), Settings::isPremiumEnabled(), Variable::isReference(), Check::logChecker(), Check::mSettings, Check::mTokenizer, SymbolDatabase::scopeList, Settings::severity, style, Token::tokAt(), Scope::type, and Token::variable().
Referenced by runChecks().
|
private |
Don't rethrow a copy of the caught exception; use a bare throw instead.
Definition at line 170 of file checkexceptionsafety.cpp.
References Token::astParent(), Scope::bodyEnd, Scope::bodyStart, Scope::eCatch, Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), Settings::isPremiumEnabled(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), rethrowCopyError(), SymbolDatabase::scopeList, Settings::severity, Token::simpleMatch(), style, Token::tokAt(), Scope::type, and Token::varId().
Referenced by runChecks().
|
inlineoverrideprivatevirtual |
wiki formatted description of the class (for –doc)
Implements Check.
Definition at line 121 of file checkexceptionsafety.h.
|
private |
deallocating memory and then throw (dead pointer)
Definition at line 95 of file checkexceptionsafety.cpp.
References Scope::bodyEnd, Scope::bodyStart, Settings::certainty, deallocThrowError(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), inconclusive, SimpleEnableGroup< T >::isEnabled(), Variable::isGlobal(), Variable::isStatic(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::scope(), Settings::severity, Token::simpleMatch(), Token::str(), and warning.
Referenced by runChecks().
|
private |
Definition at line 158 of file checkexceptionsafety.cpp.
References CWE398, normal, Check::reportError(), and warning.
Referenced by deallocThrow(), and getErrorMessages().
|
private |
Don't throw exceptions in destructors.
Definition at line 46 of file checkexceptionsafety.cpp.
References Scope::bodyEnd, Scope::bodyStart, Scope::className, destructorsError(), Function::eDestructor, Scope::function, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), Check::logChecker(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, Token::simpleMatch(), and warning.
Referenced by runChecks().
|
private |
Don't throw exceptions in destructors.
Definition at line 85 of file checkexceptionsafety.cpp.
References CWE398, normal, Check::reportError(), and warning.
Referenced by destructors(), and getErrorMessages().
|
inlineoverrideprivatevirtual |
Generate all possible errors (for –errorlist)
Implements Check.
Definition at line 104 of file checkexceptionsafety.h.
References catchExceptionByValueError(), deallocThrowError(), destructorsError(), noexceptThrowError(), rethrowCopyError(), rethrowNoCurrentExceptionError(), and unhandledExceptionSpecificationError().
|
inlinestaticprivate |
Short description of class (for –doc)
Definition at line 116 of file checkexceptionsafety.h.
|
private |
Definition at line 322 of file checkexceptionsafety.cpp.
References CWE398, error, normal, and Check::reportError().
Referenced by getErrorMessages(), and nothrowThrows().
|
private |
Check for functions that throw that shouldn't
Definition at line 287 of file checkexceptionsafety.cpp.
References Scope::function, SymbolDatabase::functionScopes, functionThrows(), Tokenizer::getSymbolDatabase(), Check::logChecker(), Check::mTokenizer, and noexceptThrowError().
Referenced by runChecks().
|
private |
Definition at line 203 of file checkexceptionsafety.cpp.
References CWE398, normal, Check::reportError(), and style.
Referenced by checkRethrowCopy(), and getErrorMessages().
|
private |
Check for rethrow not from catch scope
Definition at line 373 of file checkexceptionsafety.cpp.
References Scope::function, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Check::logChecker(), Check::mTokenizer, Token::next(), rethrowNoCurrentExceptionError(), and Token::simpleMatch().
Referenced by runChecks().
|
private |
Rethrow without currently handled exception.
Definition at line 404 of file checkexceptionsafety.cpp.
References CWE480, error, normal, and Check::reportError().
Referenced by getErrorMessages(), and rethrowNoCurrentException().
|
inlineoverrideprivatevirtual |
run checks, the token list is not simplified
Implements Check.
Definition at line 57 of file checkexceptionsafety.h.
References checkCatchExceptionByValue(), checkRethrowCopy(), deallocThrow(), destructors(), Tokenizer::getSettings(), Tokenizer::isC(), nothrowThrows(), rethrowNoCurrentException(), and unhandledExceptionSpecification().
|
private |
Check for unhandled exception specification
Definition at line 330 of file checkexceptionsafety.cpp.
References Scope::bodyEnd, Scope::bodyStart, Settings::certainty, Scope::className, Scope::function, Function::functionScope, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), inconclusive, SimpleEnableGroup< T >::isEnabled(), Library::isentrypoint(), Settings::isPremiumEnabled(), Function::isThrow(), Settings::library, Check::logChecker(), Check::mSettings, Check::mTokenizer, Function::name(), Token::next(), Settings::severity, style, Function::throwArg, Function::tokenDef, and unhandledExceptionSpecificationError().
Referenced by runChecks().
|
private |
Missing exception specification.
Definition at line 360 of file checkexceptionsafety.cpp.
References CWE703, inconclusive, Check::reportError(), Token::str(), and style.
Referenced by getErrorMessages(), and unhandledExceptionSpecification().