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

Check for bad function usage. More...

#include <checkfunctions.h>

Inheritance diagram for CheckFunctions:
Check

Public Member Functions

 CheckFunctions ()
 This constructor is used when registering the CheckFunctions. 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

 CheckFunctions (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 checkProhibitedFunctions ()
 Check for functions that should not be used. More...
 
void invalidFunctionUsage ()
 Invalid function usage (invalid input value / overlapping data) More...
 
void checkIgnoredReturnValue ()
 Check for ignored return values. More...
 
void checkMathFunctions ()
 Check for parameters given to math function that do not make sense More...
 
void memsetZeroBytes ()
 Check for filling zero bytes with memset() More...
 
void memsetInvalid2ndParam ()
 Check for invalid 2nd parameter of memset() More...
 
void returnLocalStdMove ()
 Check for copy elision by RVO|NRVO More...
 
void useStandardLibrary ()
 
void checkLibraryMatchFunctions ()
 –check-library: warn for unconfigured function calls More...
 
void checkMissingReturn ()
 Check for missing "return" More...
 
void invalidFunctionArgError (const Token *tok, const std::string &functionName, int argnr, const ValueFlow::Value *invalidValue, const std::string &validstr)
 
void invalidFunctionArgBoolError (const Token *tok, const std::string &functionName, int argnr)
 
void invalidFunctionArgStrError (const Token *tok, const std::string &functionName, nonneg int argnr)
 
void ignoredReturnValueError (const Token *tok, const std::string &function)
 
void ignoredReturnErrorCode (const Token *tok, const std::string &function)
 
void mathfunctionCallWarning (const Token *tok, const nonneg int numParam=1)
 
void mathfunctionCallWarning (const Token *tok, const std::string &oldexp, const std::string &newexp)
 
void memsetZeroBytesError (const Token *tok)
 
void memsetFloatError (const Token *tok, const std::string &var_value)
 
void memsetValueOutOfRangeError (const Token *tok, const std::string &value)
 
void missingReturnError (const Token *tok)
 
void copyElisionError (const Token *tok)
 
void useStandardLibraryError (const Token *tok, const std::string &expected)
 
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

Check for bad function usage.

Definition at line 50 of file checkfunctions.h.

Constructor & Destructor Documentation

◆ CheckFunctions() [1/2]

CheckFunctions::CheckFunctions ( )
inline

This constructor is used when registering the CheckFunctions.

Definition at line 53 of file checkfunctions.h.

◆ CheckFunctions() [2/2]

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

This constructor is used when running checks.

Definition at line 57 of file checkfunctions.h.

Member Function Documentation

◆ checkIgnoredReturnValue()

void CheckFunctions::checkIgnoredReturnValue ( )
private

◆ checkLibraryMatchFunctions()

void CheckFunctions::checkLibraryMatchFunctions ( )
private

◆ checkMathFunctions()

void CheckFunctions::checkMathFunctions ( )
private

◆ checkMissingReturn()

void CheckFunctions::checkMissingReturn ( )
private

◆ checkProhibitedFunctions()

void CheckFunctions::checkProhibitedFunctions ( )
private

◆ classInfo()

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

get information about this class, used to generate documentation

Implements Check.

Definition at line 154 of file checkfunctions.h.

◆ copyElisionError()

void CheckFunctions::copyElisionError ( const Token tok)
private

Definition at line 712 of file checkfunctions.cpp.

References performance, and Check::reportError().

Referenced by getErrorMessages(), and returnLocalStdMove().

◆ getErrorMessages()

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

◆ ignoredReturnErrorCode()

void CheckFunctions::ignoredReturnErrorCode ( const Token tok,
const std::string &  function 
)
private

Definition at line 299 of file checkfunctions.cpp.

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

Referenced by checkIgnoredReturnValue().

◆ ignoredReturnValueError()

void CheckFunctions::ignoredReturnValueError ( const Token tok,
const std::string &  function 
)
private

Definition at line 293 of file checkfunctions.cpp.

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

Referenced by checkIgnoredReturnValue(), and getErrorMessages().

◆ invalidFunctionArgBoolError()

void CheckFunctions::invalidFunctionArgBoolError ( const Token tok,
const std::string &  functionName,
int  argnr 
)
private

Definition at line 224 of file checkfunctions.cpp.

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

Referenced by getErrorMessages(), and invalidFunctionUsage().

◆ invalidFunctionArgError()

void CheckFunctions::invalidFunctionArgError ( const Token tok,
const std::string &  functionName,
int  argnr,
const ValueFlow::Value invalidValue,
const std::string &  validstr 
)
private

◆ invalidFunctionArgStrError()

void CheckFunctions::invalidFunctionArgStrError ( const Token tok,
const std::string &  functionName,
nonneg int  argnr 
)
private

Definition at line 232 of file checkfunctions.cpp.

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

Referenced by getErrorMessages(), and invalidFunctionUsage().

◆ invalidFunctionUsage()

void CheckFunctions::invalidFunctionUsage ( )
private

◆ mathfunctionCallWarning() [1/2]

void CheckFunctions::mathfunctionCallWarning ( const Token tok,
const nonneg int  numParam = 1 
)
private

◆ mathfunctionCallWarning() [2/2]

void CheckFunctions::mathfunctionCallWarning ( const Token tok,
const std::string &  oldexp,
const std::string &  newexp 
)
private

Definition at line 496 of file checkfunctions.cpp.

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

◆ memsetFloatError()

void CheckFunctions::memsetFloatError ( const Token tok,
const std::string &  var_value 
)
private

Definition at line 590 of file checkfunctions.cpp.

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

Referenced by getErrorMessages(), and memsetInvalid2ndParam().

◆ memsetInvalid2ndParam()

void CheckFunctions::memsetInvalid2ndParam ( )
private

◆ memsetValueOutOfRangeError()

void CheckFunctions::memsetValueOutOfRangeError ( const Token tok,
const std::string &  value 
)
private

Definition at line 599 of file checkfunctions.cpp.

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

Referenced by getErrorMessages(), and memsetInvalid2ndParam().

◆ memsetZeroBytes()

void CheckFunctions::memsetZeroBytes ( )
private

◆ memsetZeroBytesError()

void CheckFunctions::memsetZeroBytesError ( const Token tok)
private

Definition at line 533 of file checkfunctions.cpp.

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

Referenced by getErrorMessages(), and memsetZeroBytes().

◆ missingReturnError()

void CheckFunctions::missingReturnError ( const Token tok)
private

Definition at line 416 of file checkfunctions.cpp.

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

Referenced by checkMissingReturn(), and getErrorMessages().

◆ myName()

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

Definition at line 150 of file checkfunctions.h.

◆ returnLocalStdMove()

void CheckFunctions::returnLocalStdMove ( )
private

◆ runChecks()

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

◆ useStandardLibrary()

void CheckFunctions::useStandardLibrary ( )
private

◆ useStandardLibraryError()

void CheckFunctions::useStandardLibraryError ( const Token tok,
const std::string &  expected 
)
private

Definition at line 825 of file checkfunctions.cpp.

References Check::reportError(), and style.

Referenced by getErrorMessages(), and useStandardLibrary().


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