Mention exact function name in invalidscanf message (#5649)

This commit is contained in:
PKEuS 2016-05-26 21:10:50 +02:00
parent 2d34acae71
commit 373ac52480
2 changed files with 10 additions and 10 deletions

View File

@ -422,10 +422,10 @@ void CheckIO::invalidScanf()
void CheckIO::invalidScanfError(const Token *tok)
{
std::string fname = (tok ? tok->str() : std::string("scanf"));
reportError(tok, Severity::warning,
"invalidscanf", "scanf without field width limits can crash with huge input data.\n"
"scanf without field width limits can crash with huge input data. Add a field width "
"invalidscanf", fname + "() without field width limits can crash with huge input data.\n" +
fname + "() without field width limits can crash with huge input data. Add a field width "
"specifier to fix this problem:\n"
" %s => %20s\n"
"\n"

View File

@ -706,11 +706,11 @@ private:
" scanf(\"%dx%s\", &b, bar);\n"
" fclose(file);\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (warning) scanf without field width limits can crash with huge input data.\n"
"[test.cpp:5]: (warning) scanf without field width limits can crash with huge input data.\n"
"[test.cpp:6]: (warning) scanf without field width limits can crash with huge input data.\n"
"[test.cpp:7]: (warning) scanf without field width limits can crash with huge input data.\n"
"[test.cpp:8]: (warning) scanf without field width limits can crash with huge input data.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (warning) fscanf() without field width limits can crash with huge input data.\n"
"[test.cpp:5]: (warning) scanf() without field width limits can crash with huge input data.\n"
"[test.cpp:6]: (warning) scanf() without field width limits can crash with huge input data.\n"
"[test.cpp:7]: (warning) sscanf() without field width limits can crash with huge input data.\n"
"[test.cpp:8]: (warning) scanf() without field width limits can crash with huge input data.\n", errout.str());
}
void testScanf2() {
@ -856,7 +856,7 @@ private:
"}", true);
ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) Width 3 given in format string (no. 1) is smaller than destination buffer 'output[5]'.\n"
"[test.cpp:7]: (error) Width 5 given in format string (no. 1) is larger than destination buffer 'output[5]', use %4s to prevent overflowing it.\n"
"[test.cpp:4]: (warning) scanf without field width limits can crash with huge input data.\n", errout.str());
"[test.cpp:4]: (warning) sscanf() without field width limits can crash with huge input data.\n", errout.str());
check("void foo() {\n"
" const size_t BUFLENGTH(2048);\n"
@ -1340,7 +1340,7 @@ private:
" scanf(\"%s\n\", c);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) %s in format string (no. 1) requires a 'char *' but the argument type is 'const char *'.\n"
"[test.cpp:3]: (warning) scanf without field width limits can crash with huge input data.\n", errout.str());
"[test.cpp:3]: (warning) scanf() without field width limits can crash with huge input data.\n", errout.str());
}
}