test: Added the last buffer overrun tests

This commit is contained in:
Daniel Marjamäki 2008-08-23 16:15:31 +00:00
parent 8c901694b8
commit 7a07284c7e
1 changed files with 28 additions and 0 deletions

View File

@ -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 )