Fixed #2604 (Segmentation fault of cppcheck ( sizeof <= A ))

This commit is contained in:
Daniel Marjamäki 2011-02-23 20:44:14 +01:00
parent c3fe6f80da
commit daf0e7c37d
2 changed files with 15 additions and 1 deletions

View File

@ -3918,10 +3918,14 @@ void Tokenizer::simplifySizeof()
--parlevel; --parlevel;
if (Token::Match(tempToken, "%var%")) if (Token::Match(tempToken, "%var%"))
{ {
while (tempToken->next()->str() == "[") while (tempToken && tempToken->next() && tempToken->next()->str() == "[")
{ {
tempToken = tempToken->next()->link(); tempToken = tempToken->next()->link();
} }
if (!tempToken || !tempToken->next())
{
break;
}
if (tempToken->next()->str() == ".") if (tempToken->next()->str() == ".")
{ {

View File

@ -85,6 +85,7 @@ private:
TEST_CASE(sizeof20); // #2024 - sizeof a) TEST_CASE(sizeof20); // #2024 - sizeof a)
TEST_CASE(sizeof21); // #2232 - sizeof...(Args) TEST_CASE(sizeof21); // #2232 - sizeof...(Args)
TEST_CASE(sizeof22); // #2599 TEST_CASE(sizeof22); // #2599
TEST_CASE(sizeof23); // #2604
TEST_CASE(sizeofsizeof); TEST_CASE(sizeofsizeof);
TEST_CASE(casting); TEST_CASE(casting);
@ -1433,6 +1434,15 @@ private:
tok(code); tok(code);
} }
void sizeof23()
{
// ticket #2604 segmentation fault
const char code[] = "sizeof <= A\n";
// don't segfault
tok(code);
}
void sizeofsizeof() void sizeofsizeof()
{ {