Fixed #6398 - false negative: (warning) Unnecessary comparison of static strings.
This commit is contained in:
parent
1aa3adbb46
commit
465f74b3bb
|
@ -39,7 +39,7 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare()
|
|||
return;
|
||||
|
||||
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|strncasecmp|wcscmp|wcsncmp (")) {
|
||||
if (Token::Match(tok, "memcmp|strncmp|strcmp|stricmp|strverscmp|bcmp|strcmpi|strcasecmp|strncasecmp|wcsncasecmp|wcscasecmp|wmemcmp|wcscmp|wcsncmp (")) {
|
||||
if (Token::Match(tok->tokAt(2), "%str% , %str%")) {
|
||||
const std::string &str1 = tok->strAt(2);
|
||||
const std::string &str2 = tok->strAt(4);
|
||||
|
|
|
@ -99,15 +99,31 @@ private:
|
|||
|
||||
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"
|
||||
" if (strcmp(\"A\",\"A\")){}\n"
|
||||
" if (strncmp(\"A\",\"A\",1)){}\n"
|
||||
" if (strcasecmp(\"A\",\"A\")){}\n"
|
||||
" if (strncasecmp(\"A\",\"A\",1)){}\n"
|
||||
" if (memcmp(\"A\",\"A\",1)){}\n"
|
||||
" if (strverscmp(\"A\",\"A\")){}\n"
|
||||
" if (bcmp(\"A\",\"A\",1)){}\n"
|
||||
" if (wcsncasecmp(L\"A\",L\"A\",1)){}\n"
|
||||
" if (wcsncmp(L\"A\",L\"A\",1)){}\n"
|
||||
" if (wmemcmp(L\"A\",L\"A\",1)){}\n"
|
||||
" if (wcscmp(L\"A\",L\"A\")){}\n"
|
||||
" if (wcscasecmp(L\"A\",L\"A\")){}\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());
|
||||
"[test.cpp:5]: (warning) Unnecessary comparison of static strings.\n"
|
||||
"[test.cpp:6]: (warning) Unnecessary comparison of static strings.\n"
|
||||
"[test.cpp:7]: (warning) Unnecessary comparison of static strings.\n"
|
||||
"[test.cpp:8]: (warning) Unnecessary comparison of static strings.\n"
|
||||
"[test.cpp:9]: (warning) Unnecessary comparison of static strings.\n"
|
||||
"[test.cpp:10]: (warning) Unnecessary comparison of static strings.\n"
|
||||
"[test.cpp:11]: (warning) Unnecessary comparison of static strings.\n"
|
||||
"[test.cpp:12]: (warning) Unnecessary comparison of static strings.\n"
|
||||
"[test.cpp:13]: (warning) Unnecessary comparison of static strings.\n", errout.str());
|
||||
|
||||
check_preprocess_suppress(
|
||||
"#define MACRO \"00FF00\"\n"
|
||||
|
|
Loading…
Reference in New Issue