Fixed false positive: %Ld in format string (no. 1) requires 'long long' but the argument type is 'long long' (#7601).

This commit is contained in:
Robert Reif 2016-07-16 10:33:46 +02:00 committed by PKEuS
parent e495bfb960
commit 768c26805c
2 changed files with 15 additions and 0 deletions

View File

@ -1168,6 +1168,10 @@ void CheckIO::checkFormatString(const Token * const tok,
if (!typesMatch(argInfo.typeToken->originalName(), "ssize_t"))
invalidPrintfArgTypeError_uint(tok, numFormat, specifier, &argInfo);
break;
case 'L':
if (argInfo.typeToken->str() != "long" || !argInfo.typeToken->isLong())
invalidPrintfArgTypeError_sint(tok, numFormat, specifier, &argInfo);
break;
default:
if (!Token::Match(argInfo.typeToken, "bool|char|short|int"))
invalidPrintfArgTypeError_sint(tok, numFormat, specifier, &argInfo);
@ -1230,6 +1234,10 @@ void CheckIO::checkFormatString(const Token * const tok,
} else if (!typesMatch(argInfo.typeToken->originalName(), "size_t"))
invalidPrintfArgTypeError_uint(tok, numFormat, specifier, &argInfo);
break;
case 'L':
if (argInfo.typeToken->str() != "long" || !argInfo.typeToken->isLong())
invalidPrintfArgTypeError_uint(tok, numFormat, specifier, &argInfo);
break;
default:
if (!Token::Match(argInfo.typeToken, "bool|char|short|int"))
invalidPrintfArgTypeError_uint(tok, numFormat, specifier, &argInfo);

View File

@ -2193,6 +2193,13 @@ private:
" printf(\"%d\", s.x);\n"
"}");
ASSERT_EQUALS("", errout.str());
// Ticket #7601
check("void foo(int i, unsigned int ui, long long ll, unsigned long long ull) {\n"
" printf(\"%Ld %Lu %Ld %Lu\", i, ui, ll, ull);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long' but the argument type is 'int'.\n"
"[test.cpp:2]: (warning) %Lu in format string (no. 2) requires 'unsigned long long' but the argument type is 'unsigned int'.\n", errout.str());
}
void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings