Fixed #1576 ('Index out of bounds' false positive)
This commit is contained in:
parent
1b81a9d435
commit
9a4707c025
|
@ -968,6 +968,13 @@ void CheckBufferOverrun::checkStructVariable()
|
|||
// Found a struct declaration. Search for arrays..
|
||||
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next())
|
||||
{
|
||||
// skip inner scopes..
|
||||
if (tok2->next() && tok2->next()->str() == "{")
|
||||
{
|
||||
tok2 = tok2->next()->link();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tok2->str() == "}")
|
||||
break;
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ private:
|
|||
TEST_CASE(array_index_calculation);
|
||||
TEST_CASE(array_index_negative);
|
||||
TEST_CASE(array_index_for_decr);
|
||||
TEST_CASE(array_index_varnames); // FP: struct member. #1576
|
||||
|
||||
TEST_CASE(buffer_overrun_1);
|
||||
TEST_CASE(buffer_overrun_2);
|
||||
|
@ -1012,6 +1013,24 @@ private:
|
|||
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array 'val[5]' index -1 out of bounds\n", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void array_index_varnames()
|
||||
{
|
||||
check("struct A {\n"
|
||||
" char data[4];\n"
|
||||
" struct B { char data[3]; };\n"
|
||||
" B b;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void f()\n"
|
||||
"{\n"
|
||||
" A a;\n"
|
||||
" a.data[3] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void buffer_overrun_1()
|
||||
{
|
||||
check("void f()\n"
|
||||
|
|
Loading…
Reference in New Issue