Add strncmp to the list of static string comparison functions

This commit is contained in:
Richard Quirk 2011-10-28 22:03:18 +02:00
parent b69ad0fefc
commit 4ba6ac7332
2 changed files with 11 additions and 1 deletions

View File

@ -2255,7 +2255,7 @@ void CheckOther::checkAlwaysTrueOrFalseStringCompare()
if (!_settings->isEnabled("style") && !_settings->isEnabled("performance"))
return;
const char pattern1[] = "strcmp|stricmp|strcmpi|strcasecmp|wcscmp ( %str% , %str% )";
const char pattern1[] = "strncmp|strcmp|stricmp|strcmpi|strcasecmp|wcscmp ( %str% , %str% ";
const char pattern2[] = "QString :: compare ( %str% , %str% )";
const Token *tok = _tokenizer->tokens();

View File

@ -3418,6 +3418,16 @@ private:
" }"
"}");
ASSERT_EQUALS("", errout.str());
check_preprocess_suppress(
"int main()\n"
"{\n"
" if (strncmp(\"hotdog\",\"hotdog\", 6) == 0)"
" {"
" std::cout << \"Equal\n\""
" }"
"}");
ASSERT_EQUALS("[test.cpp:3]: (warning) Comparison of always identical static strings.\n", errout.str());
}
void check_signOfUnsignedVariable(const char code[]) {