Fixed #1627 (###### If you see this, there is a bug ###### - Token::Match('%varid% [ %num% ]', 0))

This commit is contained in:
Daniel Marjamäki 2010-04-26 18:52:40 +02:00
parent 6bb93b5eb7
commit 0444ff5298
2 changed files with 23 additions and 0 deletions

View File

@ -1670,6 +1670,8 @@ bool CheckBufferOverrun::ArrayInfo::declare(const Token *tok, const Tokenizer &t
_varname = vartok->str();
_varid = vartok->varId();
if (!varid)
return false;
const Token *atok = vartok->tokAt(2);

21
test/testbufferoverrun.cpp Executable file → Normal file
View File

@ -72,6 +72,8 @@ private:
TEST_CASE(sizeof2);
TEST_CASE(sizeof3);
TEST_CASE(arrayInfo);
TEST_CASE(array_index_1);
TEST_CASE(array_index_2);
TEST_CASE(array_index_3);
@ -271,6 +273,25 @@ private:
ASSERT_EQUALS("", errout.str());
}
void arrayInfo()
{
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr("XY(1) const int a[2] = { 1, 2 };");
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer..
errout.str("");
tokenizer.simplifySizeof();
CheckBufferOverrun::ArrayInfo ai;
ASSERT_EQUALS(false, ai.declare(tokenizer.tokens()->tokAt(5), tokenizer));
}
void array_index_1()
{
check("void f()\n"