49 :
Check(myName(), tokenizer, settings, errorLogger) {}
66 void stringLiteralWrite();
72 void checkIncorrectStringCompare();
75 void checkSuspiciousStringCompare();
78 void checkAlwaysTrueOrFalseStringCompare();
81 void overlappingStrcmp();
84 void sprintfOverlappingData();
86 void stringLiteralWriteError(
const Token *tok,
const Token *strValue);
87 void sprintfOverlappingDataError(
const Token *funcTok,
const Token *tok,
const std::string &varname);
88 void strPlusCharError(
const Token *tok);
89 void incorrectStringCompareError(
const Token *tok,
const std::string& func,
const std::string &
string);
90 void incorrectStringBooleanError(
const Token *tok,
const std::string&
string);
91 void alwaysTrueFalseStringCompareError(
const Token *tok,
const std::string& str1,
const std::string& str2);
92 void alwaysTrueStringVariableCompareError(
const Token *tok,
const std::string& str1,
const std::string& str2);
93 void suspiciousStringCompareError(
const Token* tok,
const std::string& var,
bool isLong);
94 void suspiciousStringCompareError_char(
const Token* tok,
const std::string& var);
95 void overlappingStrcmpError(
const Token* eq0,
const Token *ne0);
117 return "Detect misusage of C-style strings:\n"
118 "- overlapping buffers passed to sprintf as source and destination\n"
119 "- incorrect length arguments for 'substr' and 'strncmp'\n"
120 "- suspicious condition (runtime comparison of string literals)\n"
121 "- suspicious condition (string/char literals as boolean)\n"
122 "- suspicious comparison of a string literal with a char\\* variable\n"
123 "- suspicious comparison of '\\0' with a char\\* variable\n"
124 "- overlapping strcmp() expression\n";
Detect misusage of C-style strings and related standard functions.
void checkSuspiciousStringCompare()
Check for comparison of a string literal with a char* variable
void checkIncorrectStringCompare()
Check for using bad usage of strncmp and substr
void suspiciousStringCompareError(const Token *tok, const std::string &var, bool isLong)
void incorrectStringBooleanError(const Token *tok, const std::string &string)
void overlappingStrcmp()
Check for overlapping strcmp()
void incorrectStringCompareError(const Token *tok, const std::string &func, const std::string &string)
static std::string myName()
void strPlusCharError(const Token *tok)
void suspiciousStringCompareError_char(const Token *tok, const std::string &var)
CheckString()
This constructor is used when registering the CheckClass.
std::string classInfo() const override
get information about this class, used to generate documentation
void sprintfOverlappingData()
Check for overlapping source and destination passed to sprintf()
void stringLiteralWriteError(const Token *tok, const Token *strValue)
void alwaysTrueStringVariableCompareError(const Token *tok, const std::string &str1, const std::string &str2)
CheckString(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
This constructor is used when running checks.
void overlappingStrcmpError(const Token *eq0, const Token *ne0)
void stringLiteralWrite()
undefined behaviour, writing string literal
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override
get error messages
void strPlusChar()
str plus char (unusual pointer arithmetic)
void alwaysTrueFalseStringCompareError(const Token *tok, const std::string &str1, const std::string &str2)
void sprintfOverlappingDataError(const Token *funcTok, const Token *tok, const std::string &varname)
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override
Run checks against the normal token list.
void checkAlwaysTrueOrFalseStringCompare()
Check for suspicious code that compares string literals for equality
Interface class that cppcheck uses to communicate with the checks.
This is an interface, which the class responsible of error logging should implement.
This is just a container for general settings so that we don't need to pass individual values to func...
The token list that the TokenList generates is a linked-list of this class.
The main purpose is to tokenize the source code.
const Settings & getSettings() const