From 4ba6ac7332b04384f3a845c9c83f38460ed9f333 Mon Sep 17 00:00:00 2001 From: Richard Quirk Date: Fri, 28 Oct 2011 22:03:18 +0200 Subject: [PATCH] Add strncmp to the list of static string comparison functions --- lib/checkother.cpp | 2 +- test/testother.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d6221af7b..764a2ccaf 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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(); diff --git a/test/testother.cpp b/test/testother.cpp index 8655852cb..5b18f3470 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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[]) {