Fixed #5248 (False positive: Invalid argument in scanf for %zd)
This commit is contained in:
parent
c1c2f4bbc6
commit
d679a4c1f7
|
@ -787,7 +787,8 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, false);
|
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, false);
|
||||||
break;
|
break;
|
||||||
case 'z':
|
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);
|
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, false);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
|
@ -1625,6 +1626,9 @@ void CheckIO::invalidScanfArgTypeError_int(const Token* tok, unsigned int numFor
|
||||||
else
|
else
|
||||||
errmsg << "intmax_t";
|
errmsg << "intmax_t";
|
||||||
} else if (specifier[0] == 'z') {
|
} else if (specifier[0] == 'z') {
|
||||||
|
if (specifier[1] == 'd')
|
||||||
|
errmsg << "ptrdiff_t";
|
||||||
|
else
|
||||||
errmsg << "size_t";
|
errmsg << "size_t";
|
||||||
} else if (specifier[0] == 't') {
|
} else if (specifier[0] == 't') {
|
||||||
errmsg << (isUnsigned ? "unsigned " : "") << "ptrdiff_t";
|
errmsg << (isUnsigned ? "unsigned " : "") << "ptrdiff_t";
|
||||||
|
|
|
@ -1323,6 +1323,16 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void testPrintfArgument() {
|
||||||
|
|
Loading…
Reference in New Issue