Cppcheck
|
checks on usage of sizeof() operator More...
#include <checksizeof.h>
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 | |
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 | |
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 {} |
checks on usage of sizeof() operator
Definition at line 41 of file checksizeof.h.
|
inline |
This constructor is used when registering the CheckClass.
Definition at line 44 of file checksizeof.h.
|
inlineprivate |
This constructor is used when running checks.
Definition at line 48 of file checksizeof.h.
|
private |
Definition at line 498 of file checksizeof.cpp.
References CWE467, normal, portability, and Check::reportError().
Referenced by getErrorMessages(), and sizeofVoid().
|
private |
Check for using sizeof with array given as function argument
Definition at line 77 of file checksizeof.cpp.
References Scope::bodyEnd, Scope::bodyStart, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Variable::isArgument(), Variable::isArray(), SimpleEnableGroup< T >::isEnabled(), Variable::isReference(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, sizeofForArrayParameterError(), Token::str(), Token::variable(), and warning.
Referenced by runChecks().
|
private |
Check for using sizeof with numeric given as function argument
Definition at line 47 of file checksizeof.cpp.
References Scope::bodyEnd, Scope::bodyStart, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, sizeofForNumericParameterError(), and warning.
Referenced by runChecks().
|
private |
Check for using sizeof of a variable when allocating it
Definition at line 118 of file checksizeof.cpp.
References Token::astOperand1(), Token::astOperand2(), Scope::bodyEnd, Scope::bodyStart, ValueType::CHAR, divideBySizeofError(), SymbolDatabase::functionScopes, Library::getAllocFuncInfo(), Tokenizer::getSymbolDatabase(), Variable::isArray(), SimpleEnableGroup< T >::isEnabled(), Variable::isPointer(), Settings::library, Token::link(), Token::linkAt(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::nextArgument(), ValueType::pointer, Settings::severity, Token::simpleMatch(), sizeofForPointerError(), Token::str(), Token::strAt(), Token::tokAt(), ValueType::type, Token::valueType(), Token::variable(), Token::varId(), ValueType::VOID, and warning.
Referenced by runChecks().
|
inlineoverrideprivatevirtual |
get information about this class, used to generate documentation
Implements Check.
Definition at line 124 of file checksizeof.h.
|
private |
Definition at line 279 of file checksizeof.cpp.
References CWE682, normal, Check::reportError(), and warning.
Referenced by checkSizeofForPointerSize(), and getErrorMessages().
|
private |
Definition at line 438 of file checksizeof.cpp.
References CWE682, inconclusive, Check::reportError(), and warning.
Referenced by getErrorMessages(), and suspiciousSizeofCalculation().
|
inlineoverrideprivatevirtual |
get error messages
Implements Check.
Definition at line 104 of file checksizeof.h.
References arithOperationsOnVoidPointerError(), divideBySizeofError(), divideSizeofError(), multiplySizeofError(), sizeofCalculationError(), sizeofDereferencedVoidPointerError(), sizeofForArrayParameterError(), sizeofForNumericParameterError(), sizeofForPointerError(), sizeofFunctionError(), sizeofsizeofError(), and sizeofVoidError().
|
private |
Definition at line 432 of file checksizeof.cpp.
References CWE682, inconclusive, Check::reportError(), and warning.
Referenced by getErrorMessages(), and suspiciousSizeofCalculation().
|
inlinestaticprivate |
Definition at line 120 of file checksizeof.h.
|
inlineoverrideprivatevirtual |
Run checks against the normal token list.
Implements Check.
Definition at line 52 of file checksizeof.h.
References checkSizeofForArrayParameter(), checkSizeofForNumericParameter(), checkSizeofForPointerSize(), Tokenizer::getSettings(), sizeofCalculation(), sizeofFunction(), sizeofsizeof(), sizeofVoid(), and suspiciousSizeofCalculation().
|
private |
Check for calculations inside sizeof
Definition at line 313 of file checksizeof.cpp.
References Token::astOperand2(), Settings::certainty, inconclusive, Token::isCalculation(), SimpleEnableGroup< T >::isEnabled(), Token::isExpandedMacro(), Check::logChecker(), Check::mSettings, Check::mTokenizer, Token::next(), Token::previous(), Settings::severity, Token::simpleMatch(), sizeofCalculationError(), Token::tokAt(), Tokenizer::tokens(), and warning.
Referenced by runChecks().
|
private |
Definition at line 351 of file checksizeof.cpp.
References CWE682, inconclusive, normal, Check::reportError(), and warning.
Referenced by getErrorMessages(), and sizeofCalculation().
|
private |
Definition at line 491 of file checksizeof.cpp.
References CWE682, normal, portability, and Check::reportError().
Referenced by getErrorMessages(), and sizeofVoid().
|
private |
Definition at line 102 of file checksizeof.cpp.
References CWE467, normal, Check::reportError(), and warning.
Referenced by checkSizeofForArrayParameter(), and getErrorMessages().
|
private |
Definition at line 65 of file checksizeof.cpp.
References CWE682, normal, Check::reportError(), and warning.
Referenced by checkSizeofForNumericParameter(), and getErrorMessages().
|
private |
Definition at line 270 of file checksizeof.cpp.
References CWE467, normal, Check::reportError(), and warning.
Referenced by checkSizeofForPointerSize(), and getErrorMessages().
|
private |
Check for function call inside sizeof
Definition at line 359 of file checksizeof.cpp.
References Token::astOperand2(), Token::eName, Token::function(), Scope::functionMap, SimpleEnableGroup< T >::isEnabled(), Settings::isPremiumEnabled(), Check::logChecker(), Check::mSettings, Check::mTokenizer, Function::nestedIn, Token::next(), Token::previous(), Settings::severity, Token::simpleMatch(), sizeofFunctionError(), Token::str(), Token::tokAt(), Tokenizer::tokens(), Token::tokType(), and warning.
Referenced by runChecks().
|
private |
Definition at line 393 of file checksizeof.cpp.
References CWE682, normal, Check::reportError(), and warning.
Referenced by getErrorMessages(), and sizeofFunction().
|
private |
Check for 'sizeof sizeof ..'
Definition at line 287 of file checksizeof.cpp.
References SimpleEnableGroup< T >::isEnabled(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, sizeofsizeofError(), Tokenizer::tokens(), and warning.
Referenced by runChecks().
|
private |
Definition at line 302 of file checksizeof.cpp.
References CWE682, normal, Check::reportError(), and warning.
Referenced by getErrorMessages(), and sizeofsizeof().
|
private |
Check for using sizeof(void)
Definition at line 446 of file checksizeof.cpp.
References arithOperationsOnVoidPointerError(), SimpleEnableGroup< T >::isEnabled(), ValueType::isIntegral(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), ValueType::pointer, portability, Settings::severity, Token::simpleMatch(), sizeofDereferencedVoidPointerError(), sizeofVoidError(), ValueType::str(), Tokenizer::tokens(), and ValueType::type.
Referenced by runChecks().
|
private |
Definition at line 484 of file checksizeof.cpp.
References CWE682, normal, portability, and Check::reportError().
Referenced by getErrorMessages(), and sizeofVoid().
|
private |
Check for suspicious calculations with sizeof results
Definition at line 402 of file checksizeof.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::astParent(), Settings::certainty, divideSizeofError(), inconclusive, Variable::isArray(), SimpleEnableGroup< T >::isEnabled(), Variable::isPointer(), Token::link(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, multiplySizeofError(), Token::next(), ValueType::pointer, Settings::severity, Token::simpleMatch(), Token::str(), Tokenizer::tokens(), Variable::valueType(), Token::variable(), and warning.
Referenced by runChecks().