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:
parent
9d9a5b0623
commit
ec6edaee6e
|
@ -1196,6 +1196,16 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[8]' index 17 out of bounds\n", errout.str());
|
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()
|
void array_index_negative()
|
||||||
|
|
Loading…
Reference in New Issue