Fixed #2610 (segmentation fault of cppcheck ( if () < {} ))

This commit is contained in:
Daniel Marjamäki 2011-02-24 18:49:16 +01:00
parent db7ce1c13c
commit 9bf6e67898
2 changed files with 10 additions and 0 deletions

View File

@ -4663,6 +4663,8 @@ void Tokenizer::simplifyIfAddBraces()
break; break;
} }
tempToken = tempToken->link(); tempToken = tempToken->link();
if (!tempToken || !tempToken->next())
break;
if (tempToken->next()->isName() && tempToken->next()->str() != "else") if (tempToken->next()->isName() && tempToken->next()->str() != "else")
break; break;
continue; continue;

View File

@ -79,6 +79,7 @@ private:
TEST_CASE(ifAddBraces11); TEST_CASE(ifAddBraces11);
TEST_CASE(ifAddBraces12); TEST_CASE(ifAddBraces12);
TEST_CASE(ifAddBraces13); TEST_CASE(ifAddBraces13);
TEST_CASE(ifAddBraces14); // #2610 - segfault: if()<{}
TEST_CASE(whileAddBraces); TEST_CASE(whileAddBraces);
TEST_CASE(doWhileAddBraces); TEST_CASE(doWhileAddBraces);
@ -850,6 +851,13 @@ private:
ASSERT_EQUALS(expected2, tokenizeAndStringify(code2, true)); ASSERT_EQUALS(expected2, tokenizeAndStringify(code2, true));
} }
void ifAddBraces14()
{
// ticket #2610 (segfault)
tokenizeAndStringify("if()<{}", false);
}
void whileAddBraces() void whileAddBraces()
{ {
const char code[] = ";while(a);"; const char code[] = ";while(a);";