Added array index out of bounds tests to testsuite.

This commit is contained in:
Ettl Martin 2012-05-23 23:59:14 +02:00
parent b3d862e27e
commit ffb9342084
1 changed files with 19 additions and 5 deletions

View File

@ -302,9 +302,6 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void sizeof1() { void sizeof1() {
check("static void f()\n" check("static void f()\n"
"{\n" "{\n"
@ -342,8 +339,6 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void array_index_1() { void array_index_1() {
check("void f()\n" check("void f()\n"
"{\n" "{\n"
@ -359,6 +354,25 @@ private:
" return str[16];\n" " return str[16];\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[16]' index 16 out of bounds\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[16]' index 16 out of bounds\n", errout.str());
// test stack array
check("int f()\n"
"{\n"
" int x[ 3 ] = { 0, 1, 2 };\n"
" int y;\n"
" y = x[ 4 ];\n"
" return y;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'x[3]' index 4 out of bounds\n", errout.str());
check("int f()\n"
"{\n"
" int x[ 3 ] = { 0, 1, 2 };\n"
" int y;\n"
" y = x[ 2 ];\n"
" return y;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }