diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 6a8475af7..c42273f3c 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -448,7 +448,7 @@ void CheckIO::checkWrongPrintfScanfArguments() } else { continue; } - } else if (Token::Match(tok, "sprintf|fprintf|sscanf|fscanf|swscanf|fwprintf|fwscanf ( %any%")) { + } else if (Token::Match(tok, "sprintf|fprintf|sscanf|fscanf|swscanf|fwprintf|fwscanf ( %any%") || (Token::simpleMatch(tok, "swprintf (") && Token::Match(tok->tokAt(2)->nextArgument(), "%str%"))) { const Token* formatStringTok = tok->tokAt(2)->nextArgument(); // Find second parameter (format string) if (Token::Match(formatStringTok, "%str% ,")) { argListTok = formatStringTok->nextArgument(); // Find third parameter (first argument of va_args) @@ -459,7 +459,7 @@ void CheckIO::checkWrongPrintfScanfArguments() } else { continue; } - } else if (Token::Match(tok, "snprintf|fnprintf|swprintf (")) { + } else if (Token::Match(tok, "snprintf|fnprintf (") || (Token::simpleMatch(tok, "swprintf (") && !Token::Match(tok->tokAt(2)->nextArgument(), "%str%"))) { const Token* formatStringTok = tok->tokAt(2); for (int i = 0; i < 2 && formatStringTok; i++) { formatStringTok = formatStringTok->nextArgument(); // Find third parameter (format string) diff --git a/test/testio.cpp b/test/testio.cpp index 8377989da..0aa286210 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -577,6 +577,15 @@ private: "[test.cpp:3]: (warning) printf format string has 1 parameters but 2 are given.\n" "[test.cpp:4]: (warning) printf format string has 2 parameters but 3 are given.\n", errout.str()); + check("void foo() {\n" // swprintf exists as MSVC extension and as standard function: #4790 + " swprintf(string1, L\"%u\", 32, string2);\n" // MSVC implementation + " swprintf(string1, L\"%s%s\", L\"a\", string2);\n" // MSVC implementation + " swprintf(string1, 6, L\"%u\", 32, string2);\n" // Standard implementation + " swprintf(string1, 6, L\"%u%s\", 32, string2);\n" // Standard implementation + "}"); + ASSERT_EQUALS("[test.cpp:2]: (warning) swprintf format string has 1 parameters but 2 are given.\n" + "[test.cpp:4]: (warning) swprintf format string has 1 parameters but 2 are given.\n", errout.str()); + check("void foo(char *str) {\n" " printf(\"%u\", 0);\n" " printf(\"%u%s\", 123, bar());\n" diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 850c6fd46..af802e249 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -539,7 +539,7 @@ private: ASSERT(false == v.isPointer()); ASSERT(true == v.isReference()); ASSERT(true == v.isRValueReference()); - ASSERT(var.tokens()->tokAt(2)->scope()); + ASSERT(var.tokens()->tokAt(2)->scope() != 0); } void staticMemberVar() {