Fixed #6388: Support strncasecmp
This commit is contained in:
parent
c4fd8919a2
commit
d53f2f583c
|
@ -39,7 +39,7 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|wcscmp|wcsncmp (")) {
|
if (Token::Match(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|strncasecmp|wcscmp|wcsncmp (")) {
|
||||||
if (Token::Match(tok->tokAt(2), "%str% , %str%")) {
|
if (Token::Match(tok->tokAt(2), "%str% , %str%")) {
|
||||||
const std::string &str1 = tok->strAt(2);
|
const std::string &str1 = tok->strAt(2);
|
||||||
const std::string &str2 = tok->strAt(4);
|
const std::string &str2 = tok->strAt(4);
|
||||||
|
|
|
@ -98,6 +98,17 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void alwaysTrueFalseStringCompare() {
|
void alwaysTrueFalseStringCompare() {
|
||||||
|
check("void f() {\n"
|
||||||
|
" if (strcmp(\"A\",\"A\") == 0){}\n"
|
||||||
|
" if (strncmp(\"A\",\"A\",1) == 0){}\n"
|
||||||
|
" if (strcasecmp(\"A\",\"A\") == 0){}\n"
|
||||||
|
" if (strncasecmp(\"A\",\"A\",1) == 0){}\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Unnecessary comparison of static strings.\n"
|
||||||
|
"[test.cpp:3]: (warning) Unnecessary comparison of static strings.\n"
|
||||||
|
"[test.cpp:4]: (warning) Unnecessary comparison of static strings.\n"
|
||||||
|
"[test.cpp:5]: (warning) Unnecessary comparison of static strings.\n", errout.str());
|
||||||
|
|
||||||
check_preprocess_suppress(
|
check_preprocess_suppress(
|
||||||
"#define MACRO \"00FF00\"\n"
|
"#define MACRO \"00FF00\"\n"
|
||||||
"int main()\n"
|
"int main()\n"
|
||||||
|
|
Loading…
Reference in New Issue