Buffer overflow: Added unit test that makes sure that array index out of bounds is detected inside loop. Ticket: #2199

This commit is contained in:
Daniel Marjamäki 2010-11-21 12:24:57 +01:00
parent 9d9a5b0623
commit ec6edaee6e
1 changed files with 10 additions and 0 deletions

View File

@ -1196,6 +1196,16 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[8]' index 17 out of bounds\n", errout.str());
// #2199 - false negative: array out of bounds in loop when there is calculation
check("void f()\n"
"{\n"
" char arr[5];\n"
" for (int i = 0; i < 5; ++i) {\n"
" arr[i + 7] = 0;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'arr[5]' index 11 out of bounds\n", errout.str());
}
void array_index_negative()