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

Check exception safety (exceptions shouldn't cause leaks nor corrupt data) More...

#include <checkexceptionsafety.h>

Inheritance diagram for CheckExceptionSafety:
Check

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
 
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

 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 {}
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CheckExceptionSafety() [1/2]

CheckExceptionSafety::CheckExceptionSafety ( )
inline

This constructor is used when registering the CheckClass.

Definition at line 50 of file checkexceptionsafety.h.

◆ CheckExceptionSafety() [2/2]

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

This constructor is used when running checks.

Definition at line 54 of file checkexceptionsafety.h.

Member Function Documentation

◆ catchExceptionByValueError()

void CheckExceptionSafety::catchExceptionByValueError ( const Token tok)
private

Definition at line 235 of file checkexceptionsafety.cpp.

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

Referenced by checkCatchExceptionByValue(), and getErrorMessages().

◆ checkCatchExceptionByValue()

void CheckExceptionSafety::checkCatchExceptionByValue ( )
private

◆ checkRethrowCopy()

void CheckExceptionSafety::checkRethrowCopy ( )
private

◆ classInfo()

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

wiki formatted description of the class (for –doc)

Implements Check.

Definition at line 121 of file checkexceptionsafety.h.

◆ deallocThrow()

void CheckExceptionSafety::deallocThrow ( )
private

◆ deallocThrowError()

void CheckExceptionSafety::deallocThrowError ( const Token *const  tok,
const std::string &  varname 
)
private

Definition at line 158 of file checkexceptionsafety.cpp.

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

Referenced by deallocThrow(), and getErrorMessages().

◆ destructors()

void CheckExceptionSafety::destructors ( )
private

◆ destructorsError()

void CheckExceptionSafety::destructorsError ( const Token *const  tok,
const std::string &  className 
)
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().

◆ getErrorMessages()

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

◆ myName()

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

Short description of class (for –doc)

Definition at line 116 of file checkexceptionsafety.h.

◆ noexceptThrowError()

void CheckExceptionSafety::noexceptThrowError ( const Token *const  tok)
private

Definition at line 322 of file checkexceptionsafety.cpp.

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

Referenced by getErrorMessages(), and nothrowThrows().

◆ nothrowThrows()

void CheckExceptionSafety::nothrowThrows ( )
private

◆ rethrowCopyError()

void CheckExceptionSafety::rethrowCopyError ( const Token *const  tok,
const std::string &  varname 
)
private

Definition at line 203 of file checkexceptionsafety.cpp.

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

Referenced by checkRethrowCopy(), and getErrorMessages().

◆ rethrowNoCurrentException()

void CheckExceptionSafety::rethrowNoCurrentException ( )
private

◆ rethrowNoCurrentExceptionError()

void CheckExceptionSafety::rethrowNoCurrentExceptionError ( const Token tok)
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().

◆ runChecks()

void CheckExceptionSafety::runChecks ( const Tokenizer ,
ErrorLogger  
)
inlineoverrideprivatevirtual

◆ unhandledExceptionSpecification()

void CheckExceptionSafety::unhandledExceptionSpecification ( )
private

◆ unhandledExceptionSpecificationError()

void CheckExceptionSafety::unhandledExceptionSpecificationError ( const Token *const  tok1,
const Token *const  tok2,
const std::string &  funcname 
)
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().


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