diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 2df5633bb..ecbda6504 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -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); diff --git a/test/testio.cpp b/test/testio.cpp index 2f0cf774c..ceba9b64e 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -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