CheckIO: Fixed false positive when using wchar_t (#5051)

This commit is contained in:
Robert Reif 2013-09-29 15:25:18 +02:00 committed by Daniel Marjamäki
parent 0527aefb11
commit d3798958f4
2 changed files with 6 additions and 2 deletions

View File

@ -859,7 +859,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
if (argInfo.isArrayOrPointer() && !argInfo.element) {
// use %p on pointers and arrays
invalidPrintfArgTypeError_int(tok, numFormat, specifier, &argInfo);
} else if (!Token::Match(argInfo.typeToken, "bool|short|long|int|char"))
} else if (!Token::Match(argInfo.typeToken, "bool|short|long|int|char|wchar_t"))
invalidPrintfArgTypeError_int(tok, numFormat, specifier, &argInfo);
else {
switch (specifier[0]) {
@ -895,7 +895,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
invalidPrintfArgTypeError_int(tok, numFormat, specifier, &argInfo);
break;
default:
if (!Token::Match(argInfo.typeToken, "bool|char|short|int"))
if (!Token::Match(argInfo.typeToken, "bool|char|short|wchar_t|int"))
invalidPrintfArgTypeError_int(tok, numFormat, specifier, &argInfo);
break;
}

View File

@ -2030,6 +2030,10 @@ private:
"[test.cpp:3]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long'.\n"
"[test.cpp:3]: (warning) %x in format string (no. 3) requires 'unsigned int' but the argument type is 'unsigned long'.\n", errout.str());
check("void foo (wchar_t c) {\n" // ticket #5051 false positive
" printf(\"%c\", c);\n"
"}\n", false, false, Settings::Win64);
ASSERT_EQUALS("", errout.str());
}
void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings