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

checks on usage of sizeof() operator More...

#include <checksizeof.h>

Inheritance diagram for CheckSizeof:
Check

Public Member Functions

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

 CheckSizeof (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 sizeofsizeof ()
 Check for 'sizeof sizeof ..' More...
 
void sizeofCalculation ()
 Check for calculations inside sizeof More...
 
void sizeofFunction ()
 Check for function call inside sizeof More...
 
void suspiciousSizeofCalculation ()
 Check for suspicious calculations with sizeof results More...
 
void checkSizeofForArrayParameter ()
 Check for using sizeof with array given as function argument More...
 
void checkSizeofForPointerSize ()
 Check for using sizeof of a variable when allocating it More...
 
void checkSizeofForNumericParameter ()
 Check for using sizeof with numeric given as function argument More...
 
void sizeofVoid ()
 Check for using sizeof(void) More...
 
void sizeofsizeofError (const Token *tok)
 
void sizeofCalculationError (const Token *tok, bool inconclusive)
 
void sizeofFunctionError (const Token *tok)
 
void multiplySizeofError (const Token *tok)
 
void divideSizeofError (const Token *tok)
 
void sizeofForArrayParameterError (const Token *tok)
 
void sizeofForPointerError (const Token *tok, const std::string &varname)
 
void divideBySizeofError (const Token *tok, const std::string &memfunc)
 
void sizeofForNumericParameterError (const Token *tok)
 
void sizeofVoidError (const Token *tok)
 
void sizeofDereferencedVoidPointerError (const Token *tok, const std::string &varname)
 
void arithOperationsOnVoidPointerError (const Token *tok, const std::string &varname, const std::string &vartype)
 
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 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

checks on usage of sizeof() operator

Definition at line 41 of file checksizeof.h.

Constructor & Destructor Documentation

◆ CheckSizeof() [1/2]

CheckSizeof::CheckSizeof ( )
inline

This constructor is used when registering the CheckClass.

Definition at line 44 of file checksizeof.h.

◆ CheckSizeof() [2/2]

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

This constructor is used when running checks.

Definition at line 48 of file checksizeof.h.

Member Function Documentation

◆ arithOperationsOnVoidPointerError()

void CheckSizeof::arithOperationsOnVoidPointerError ( const Token tok,
const std::string &  varname,
const std::string &  vartype 
)
private

Definition at line 498 of file checksizeof.cpp.

References CWE467, normal, portability, and Check::reportError().

Referenced by getErrorMessages(), and sizeofVoid().

◆ checkSizeofForArrayParameter()

void CheckSizeof::checkSizeofForArrayParameter ( )
private

◆ checkSizeofForNumericParameter()

void CheckSizeof::checkSizeofForNumericParameter ( )
private

◆ checkSizeofForPointerSize()

void CheckSizeof::checkSizeofForPointerSize ( )
private

◆ classInfo()

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

get information about this class, used to generate documentation

Implements Check.

Definition at line 124 of file checksizeof.h.

◆ divideBySizeofError()

void CheckSizeof::divideBySizeofError ( const Token tok,
const std::string &  memfunc 
)
private

Definition at line 279 of file checksizeof.cpp.

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

Referenced by checkSizeofForPointerSize(), and getErrorMessages().

◆ divideSizeofError()

void CheckSizeof::divideSizeofError ( const Token tok)
private

Definition at line 438 of file checksizeof.cpp.

References CWE682, inconclusive, Check::reportError(), and warning.

Referenced by getErrorMessages(), and suspiciousSizeofCalculation().

◆ getErrorMessages()

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

◆ multiplySizeofError()

void CheckSizeof::multiplySizeofError ( const Token tok)
private

Definition at line 432 of file checksizeof.cpp.

References CWE682, inconclusive, Check::reportError(), and warning.

Referenced by getErrorMessages(), and suspiciousSizeofCalculation().

◆ myName()

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

Definition at line 120 of file checksizeof.h.

◆ runChecks()

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

◆ sizeofCalculation()

void CheckSizeof::sizeofCalculation ( )
private

◆ sizeofCalculationError()

void CheckSizeof::sizeofCalculationError ( const Token tok,
bool  inconclusive 
)
private

Definition at line 351 of file checksizeof.cpp.

References CWE682, inconclusive, normal, Check::reportError(), and warning.

Referenced by getErrorMessages(), and sizeofCalculation().

◆ sizeofDereferencedVoidPointerError()

void CheckSizeof::sizeofDereferencedVoidPointerError ( const Token tok,
const std::string &  varname 
)
private

Definition at line 491 of file checksizeof.cpp.

References CWE682, normal, portability, and Check::reportError().

Referenced by getErrorMessages(), and sizeofVoid().

◆ sizeofForArrayParameterError()

void CheckSizeof::sizeofForArrayParameterError ( const Token tok)
private

Definition at line 102 of file checksizeof.cpp.

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

Referenced by checkSizeofForArrayParameter(), and getErrorMessages().

◆ sizeofForNumericParameterError()

void CheckSizeof::sizeofForNumericParameterError ( const Token tok)
private

Definition at line 65 of file checksizeof.cpp.

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

Referenced by checkSizeofForNumericParameter(), and getErrorMessages().

◆ sizeofForPointerError()

void CheckSizeof::sizeofForPointerError ( const Token tok,
const std::string &  varname 
)
private

Definition at line 270 of file checksizeof.cpp.

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

Referenced by checkSizeofForPointerSize(), and getErrorMessages().

◆ sizeofFunction()

void CheckSizeof::sizeofFunction ( )
private

◆ sizeofFunctionError()

void CheckSizeof::sizeofFunctionError ( const Token tok)
private

Definition at line 393 of file checksizeof.cpp.

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

Referenced by getErrorMessages(), and sizeofFunction().

◆ sizeofsizeof()

void CheckSizeof::sizeofsizeof ( )
private

◆ sizeofsizeofError()

void CheckSizeof::sizeofsizeofError ( const Token tok)
private

Definition at line 302 of file checksizeof.cpp.

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

Referenced by getErrorMessages(), and sizeofsizeof().

◆ sizeofVoid()

void CheckSizeof::sizeofVoid ( )
private

◆ sizeofVoidError()

void CheckSizeof::sizeofVoidError ( const Token tok)
private

Definition at line 484 of file checksizeof.cpp.

References CWE682, normal, portability, and Check::reportError().

Referenced by getErrorMessages(), and sizeofVoid().

◆ suspiciousSizeofCalculation()

void CheckSizeof::suspiciousSizeofCalculation ( )
private

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