Skip to content

Commit 3dd800a

Browse files
authored
Fixed #13527 - FN: stringCompare (wcsicmp) (danmar#7186)
1 parent 569fde0 commit 3dd800a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/checkstring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare()
102102
logChecker("CheckString::checkAlwaysTrueOrFalseStringCompare"); // warning
103103

104104
for (const Token* tok = mTokenizer->tokens(); tok; tok = tok->next()) {
105-
if (tok->isName() && tok->strAt(1) == "(" && Token::Match(tok, "memcmp|strncmp|strcmp|stricmp|strverscmp|bcmp|strcmpi|strcasecmp|strncasecmp|strncasecmp_l|strcasecmp_l|wcsncasecmp|wcscasecmp|wmemcmp|wcscmp|wcscasecmp_l|wcsncasecmp_l|wcsncmp|_mbscmp|_mbscmp_l|_memicmp|_memicmp_l|_stricmp|_wcsicmp|_mbsicmp|_stricmp_l|_wcsicmp_l|_mbsicmp_l")) {
105+
if (tok->isName() && tok->strAt(1) == "(" && Token::Match(tok, "memcmp|strncmp|strcmp|stricmp|strverscmp|bcmp|strcmpi|strcasecmp|strncasecmp|strncasecmp_l|strcasecmp_l|wcsncasecmp|wcscasecmp|wmemcmp|wcscmp|wcscasecmp_l|wcsncasecmp_l|wcsncmp|_mbscmp|_mbscmp_l|_memicmp|_memicmp_l|_stricmp|_wcsicmp|wcsicmp|_mbsicmp|_stricmp_l|_wcsicmp_l|_mbsicmp_l")) {
106106
if (Token::Match(tok->tokAt(2), "%str% , %str% ,|)")) {
107107
const std::string &str1 = tok->strAt(2);
108108
const std::string &str2 = tok->strAt(4);

test/teststring.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ class TestString : public TestFixture {
197197
"}");
198198
ASSERT_EQUALS("", errout_str());
199199

200+
check("int f(void) {\n" // #13527
201+
" const wchar_t* str1 = L\"Hello\";\n"
202+
" return wcsicmp(str1, str1);\n" // <<
203+
"}");
204+
ASSERT_EQUALS("[test.cpp:3]: (warning) Comparison of identical string variables.\n", errout_str());
205+
200206
check("int main()\n"
201207
"{\n"
202208
" if (strcmp(\"00FF00\", \"00FF00\") == 0)"

0 commit comments

Comments
 (0)