diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 9849754da..5d6509789 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -787,7 +787,8 @@ void CheckIO::checkWrongPrintfScanfArguments() invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, false); break; case 'z': - if (argInfo.typeToken->originalName() != "size_t") + if (argInfo.typeToken->originalName() != "ptrdiff_t" && + argInfo.typeToken->originalName() != "ssize_t") invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, false); break; case 't': @@ -1625,7 +1626,10 @@ void CheckIO::invalidScanfArgTypeError_int(const Token* tok, unsigned int numFor else errmsg << "intmax_t"; } else if (specifier[0] == 'z') { - errmsg << "size_t"; + if (specifier[1] == 'd') + errmsg << "ptrdiff_t"; + else + errmsg << "size_t"; } else if (specifier[0] == 't') { errmsg << (isUnsigned ? "unsigned " : "") << "ptrdiff_t"; } else if (specifier[0] == 'L') { diff --git a/test/testio.cpp b/test/testio.cpp index 5398e9614..254dd0f8b 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -1323,6 +1323,16 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("void g() {\n" // #5348 + " size_t s1;\n" + " ptrdiff_t s2;\n" + " ssize_t s3;\n" + " scanf(\"%zd\", &s1);\n" + " scanf(\"%zd\", &s2);\n" + " scanf(\"%zd\", &s3);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:5]: (warning) %zd in format string (no. 1) requires 'ptrdiff_t *' but the argument type is 'size_t * {aka unsigned long *}'.\n", errout.str()); + } void testPrintfArgument() {