Distinguish between different swprintf overloads. (#4790)

Fixed MSVC warning recently introduced
This commit is contained in:
PKEuS 2013-05-14 02:06:16 -07:00
parent 1903585ea3
commit b58e1241dc
3 changed files with 12 additions and 3 deletions

View File

@ -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)

View File

@ -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"

View File

@ -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() {