Added test case for #1333 (Detect access out of bounds 'for (i = 100; i > 0; --i) a[i] = 0;')

http://sourceforge.net/apps/trac/cppcheck/ticket/1333
This commit is contained in:
Reijo Tomperi 2010-01-31 22:02:26 +02:00
parent 1375a60e3f
commit db2aff03c7
1 changed files with 13 additions and 0 deletions

View File

@ -97,6 +97,7 @@ private:
TEST_CASE(array_index_switch_in_for);
TEST_CASE(array_index_calculation);
TEST_CASE(array_index_negative);
TEST_CASE(array_index_for_decr);
TEST_CASE(buffer_overrun_1);
TEST_CASE(buffer_overrun_2);
@ -850,6 +851,18 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'data[8]' index -1 out of bounds\n", errout.str());
}
void array_index_for_decr()
{
check("void f()\n"
"{\n"
" char data[8];\n"
" for (int i = 10; i > 0; --i) {\n"
" data[i] = 0;\n"
" }\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array index out of bounds\n", errout.str());
}
void buffer_overrun_1()
{
check("void f()\n"