diff --git a/testbufferoverrun.cpp b/testbufferoverrun.cpp index 9e907b722..1761e489c 100644 --- a/testbufferoverrun.cpp +++ b/testbufferoverrun.cpp @@ -50,6 +50,8 @@ public: TEST_CASE( array_index_10 ); TEST_CASE( array_index_11 ); //TEST_CASE( array_index_12 ); + + TEST_CASE( buffer_overrun_1 ); } @@ -285,6 +287,32 @@ public: } + void buffer_overrun_1() + { + check( "void f()\n" + "{\n" + " char str[3];\n" + " strcpy(str, \"abc\");\n" + "}\n" ); + ASSERT_EQUALS( std::string("[test.cpp:4]: Buffer overrun\n"), errout.str() ); + } + + + void buffer_overrun_2() + { + check( "struct ABC\n" + "{\n" + " char str[5];\n" + "};\n" + "\n" + "static void f(ABC *abc)\n" + "{\n" + " strcpy( abc->str, \"abcdef\" );\n" + "}\n" ); + ASSERT_EQUALS( std::string("[test.cpp:8]: Buffer overrun\n"), errout.str() ); + } + + }; REGISTER_FIXTURE( TestBufferOverrun )