diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index a56b828d5..f24221b22 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -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|wcscmp|wcsncmp (")) { + if (Token::Match(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|strncasecmp|wcscmp|wcsncmp (")) { if (Token::Match(tok->tokAt(2), "%str% , %str%")) { const std::string &str1 = tok->strAt(2); const std::string &str2 = tok->strAt(4); diff --git a/test/teststring.cpp b/test/teststring.cpp index 0e1b1ad7b..fcbd5fb60 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -98,6 +98,17 @@ 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" + "}"); + 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( "#define MACRO \"00FF00\"\n" "int main()\n"