Fixed #5264 (Size specifier in printf functions is wrong for some types)

This commit is contained in:
Robert Reif 2014-01-03 15:58:45 +01:00 committed by Daniel Marjamäki
parent 10ff45b54a
commit cbe3862599
2 changed files with 19 additions and 2 deletions

View File

@ -1038,8 +1038,13 @@ void CheckIO::checkWrongPrintfScanfArguments()
} else if (specifier.find("I32") != std::string::npos) {
if (argInfo.typeToken->str() != "int" || argInfo.typeToken->isLong())
invalidPrintfArgTypeError_int(tok, numFormat, specifier, &argInfo);
} else if (!(argInfo.typeToken->originalName() != "size_t" ||
argInfo.typeToken->originalName() != "ptrdiff_t"))
} else if (!(argInfo.typeToken->originalName() == "size_t" ||
argInfo.typeToken->originalName() == "ptrdiff_t" ||
argInfo.typeToken->originalName() == "WPARAM" ||
argInfo.typeToken->originalName() == "UINT_PTR" ||
argInfo.typeToken->originalName() == "LONG_PTR" ||
argInfo.typeToken->originalName() == "LPARAM" ||
argInfo.typeToken->originalName() == "LRESULT"))
invalidPrintfArgTypeError_int(tok, numFormat, specifier, &argInfo);
break;
default:

View File

@ -2205,6 +2205,18 @@ private:
"[test.cpp:15]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\n"
"[test.cpp:16]: (warning) 'I32' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\n"
"[test.cpp:17]: (warning) 'I64' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\n", errout.str());
// ticket #5264
check("void foo(LPARAM lp, WPARAM wp, LRESULT lr) {\n"
" printf(\"%Ix %Ix %Ix\", lp, wp, lr);\n"
"}\n", false, false, Settings::Win64);
ASSERT_EQUALS("", errout.str());
check("void foo(LPARAM lp, WPARAM wp, LRESULT lr) {\n"
" printf(\"%Ix %Ix %Ix\", lp, wp, lr);\n"
"}\n", false, false, Settings::Win32A);
ASSERT_EQUALS("", errout.str());
}
void testMicrosoftScanfArgument() {