Fixed #1536 (###### If you see this, there is a bug ###### Token::Match() - varid was 0)

This commit is contained in:
Robert Reif 2010-03-29 17:25:38 +02:00 committed by Daniel Marjamäki
parent c3edc5fd89
commit 0bddd1977f
2 changed files with 15 additions and 0 deletions

View File

@ -816,6 +816,10 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
if (tok->next()->str() == "*")
++varpos;
// make sure the variable is defined
if (tok->tokAt(varpos + 2)->varId() == 0)
continue; // FIXME we loose the check for negative index when we bail
// get maximum size from type
// find where this token is defined
const Token *index_type = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->tokAt(varpos + 2)->varId());

View File

@ -94,6 +94,7 @@ private:
TEST_CASE(array_index_22);
TEST_CASE(array_index_23);
TEST_CASE(array_index_24); // ticket #1492
TEST_CASE(array_index_25); // ticket #1536
TEST_CASE(array_index_multidim);
TEST_CASE(array_index_switch_in_for);
TEST_CASE(array_index_calculation);
@ -794,6 +795,16 @@ private:
"[test.cpp:4]: (error) Array 'a[65536]' index 65536 out of bounds\n", errout.str());
}
void array_index_25()
{
// ticket #1536
check("void foo()\n"
"{\n"
" long l[SOME_SIZE];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void array_index_multidim()
{
check("void f()\n"