From 373ac524809eaf96496719551f6c08c795bb4d60 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 26 May 2016 21:10:50 +0200 Subject: [PATCH] Mention exact function name in invalidscanf message (#5649) --- lib/checkio.cpp | 6 +++--- test/testio.cpp | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index a6f6d7e40..1bdbba1b7 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -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" diff --git a/test/testio.cpp b/test/testio.cpp index fc97efee6..a9216db12 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -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()); } }