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

Detect misusage of C-style strings and related standard functions. More...

#include <checkstring.h>

Inheritance diagram for CheckString:
Check

Public Member Functions

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

 CheckString (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 stringLiteralWrite ()
 undefined behaviour, writing string literal More...
 
void strPlusChar ()
 str plus char (unusual pointer arithmetic) More...
 
void checkIncorrectStringCompare ()
 Check for using bad usage of strncmp and substr More...
 
void checkSuspiciousStringCompare ()
 Check for comparison of a string literal with a char* variable More...
 
void checkAlwaysTrueOrFalseStringCompare ()
 Check for suspicious code that compares string literals for equality More...
 
void overlappingStrcmp ()
 Check for overlapping strcmp() More...
 
void sprintfOverlappingData ()
 Check for overlapping source and destination passed to sprintf() More...
 
void stringLiteralWriteError (const Token *tok, const Token *strValue)
 
void sprintfOverlappingDataError (const Token *funcTok, const Token *tok, const std::string &varname)
 
void strPlusCharError (const Token *tok)
 
void incorrectStringCompareError (const Token *tok, const std::string &func, const std::string &string)
 
void incorrectStringBooleanError (const Token *tok, const std::string &string)
 
void alwaysTrueFalseStringCompareError (const Token *tok, const std::string &str1, const std::string &str2)
 
void alwaysTrueStringVariableCompareError (const Token *tok, const std::string &str1, const std::string &str2)
 
void suspiciousStringCompareError (const Token *tok, const std::string &var, bool isLong)
 
void suspiciousStringCompareError_char (const Token *tok, const std::string &var)
 
void overlappingStrcmpError (const Token *eq0, const Token *ne0)
 
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

Detect misusage of C-style strings and related standard functions.

Definition at line 41 of file checkstring.h.

Constructor & Destructor Documentation

◆ CheckString() [1/2]

CheckString::CheckString ( )
inline

This constructor is used when registering the CheckClass.

Definition at line 44 of file checkstring.h.

◆ CheckString() [2/2]

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

This constructor is used when running checks.

Definition at line 48 of file checkstring.h.

Member Function Documentation

◆ alwaysTrueFalseStringCompareError()

void CheckString::alwaysTrueFalseStringCompareError ( const Token tok,
const std::string &  str1,
const std::string &  str2 
)
private

◆ alwaysTrueStringVariableCompareError()

void CheckString::alwaysTrueStringVariableCompareError ( const Token tok,
const std::string &  str1,
const std::string &  str2 
)
private

Definition at line 153 of file checkstring.cpp.

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

Referenced by checkAlwaysTrueOrFalseStringCompare(), and getErrorMessages().

◆ checkAlwaysTrueOrFalseStringCompare()

void CheckString::checkAlwaysTrueOrFalseStringCompare ( )
private

◆ checkIncorrectStringCompare()

void CheckString::checkIncorrectStringCompare ( )
private

◆ checkSuspiciousStringCompare()

void CheckString::checkSuspiciousStringCompare ( )
private

◆ classInfo()

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

get information about this class, used to generate documentation

Implements Check.

Definition at line 116 of file checkstring.h.

◆ getErrorMessages()

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

◆ incorrectStringBooleanError()

void CheckString::incorrectStringBooleanError ( const Token tok,
const std::string &  string 
)
private

◆ incorrectStringCompareError()

void CheckString::incorrectStringCompareError ( const Token tok,
const std::string &  func,
const std::string &  string 
)
private

Definition at line 325 of file checkstring.cpp.

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

Referenced by checkIncorrectStringCompare(), and getErrorMessages().

◆ myName()

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

Definition at line 112 of file checkstring.h.

◆ overlappingStrcmp()

void CheckString::overlappingStrcmp ( )
private

◆ overlappingStrcmpError()

void CheckString::overlappingStrcmpError ( const Token eq0,
const Token ne0 
)
private

◆ runChecks()

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

◆ sprintfOverlappingData()

void CheckString::sprintfOverlappingData ( )
private

◆ sprintfOverlappingDataError()

void CheckString::sprintfOverlappingDataError ( const Token funcTok,
const Token tok,
const std::string &  varname 
)
private

Definition at line 461 of file checkstring.cpp.

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

Referenced by getErrorMessages(), and sprintfOverlappingData().

◆ stringLiteralWrite()

void CheckString::stringLiteralWrite ( )
private

◆ stringLiteralWriteError()

void CheckString::stringLiteralWriteError ( const Token tok,
const Token strValue 
)
private

Definition at line 74 of file checkstring.cpp.

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

Referenced by getErrorMessages(), and stringLiteralWrite().

◆ strPlusChar()

void CheckString::strPlusChar ( )
private

◆ strPlusCharError()

void CheckString::strPlusCharError ( const Token tok)
private

Definition at line 244 of file checkstring.cpp.

References Token::astOperand2(), CWE665, Token::eChar, error, normal, and Check::reportError().

Referenced by getErrorMessages(), and strPlusChar().

◆ suspiciousStringCompareError()

void CheckString::suspiciousStringCompareError ( const Token tok,
const std::string &  var,
bool  isLong 
)
private

Definition at line 205 of file checkstring.cpp.

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

Referenced by checkSuspiciousStringCompare(), and getErrorMessages().

◆ suspiciousStringCompareError_char()

void CheckString::suspiciousStringCompareError_char ( const Token tok,
const std::string &  var 
)
private

Definition at line 212 of file checkstring.cpp.

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

Referenced by checkSuspiciousStringCompare(), and getErrorMessages().


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