diff --git a/test/cfg/std.c b/test/cfg/std.c index 6859b6b00..3de9f76f4 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -22,7 +22,12 @@ void bufferAccessOutOf(void) { strncpy(a,"abcde",5); // cppcheck-suppress bufferAccessOutOfBounds strncpy(a,"abcde",6); - + fread(a,1,5,stdin); + // cppcheck-suppress bufferAccessOutOfBounds + fread(a,1,6,stdin); + fwrite(a,1,5,stdout); + // cppcheck-suppress bufferAccessOutOfBounds + fread(a,1,6,stdout); } // null pointer diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index c0889c759..4d06bf26c 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -289,6 +289,7 @@ private: TEST_CASE(counter_test); TEST_CASE(minsize_argvalue); TEST_CASE(minsize_sizeof); + TEST_CASE(minsize_mul); TEST_CASE(unknownType); TEST_CASE(terminateStrncpy1); @@ -2226,32 +2227,6 @@ private: void buffer_overrun_1_standard_functions() { - // fread - checkstd("void f(FILE* fd) {\n" - " char str[3];\n" - " fread(str,1,4,fd);\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout.str()); - - checkstd("void f(FILE* fd) {\n" - " char str[3];\n" - " fread(str,1,3,fd);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - // fwrite - checkstd("void f(FILE* fd) {\n" - " char str[3];\n" - " fwrite(str,1,4,fd);\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout.str()); - - checkstd("void f(FILE* fd) {\n" - " char str[3];\n" - " fwrite(str,1,3,fd);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - // #4968 - not standard function checkstd("void f() {\n" " char str[3];\n" @@ -3806,6 +3781,36 @@ private: ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Buffer is accessed out of bounds: buf\n", errout.str()); } + void minsize_mul() { + Settings settings; + const char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; + tinyxml2::XMLDocument doc; + doc.Parse(xmldata, sizeof(xmldata)); + settings.library.load(doc); + + check("void f() {\n" + " char c[5];\n" + " fread(c, 1, 5, stdin);\n" + "}", settings); + ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" + " char c[5];\n" + " fread(c, 1, 6, stdin);\n" + "}", settings); + ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout.str()); + } + void unknownType() { check("void f()\n" "{\n"