Fixed #2168 (Segmentation fault of cppcheck)

This commit is contained in:
Robert Reif 2010-11-04 17:54:04 +01:00 committed by Daniel Marjamäki
parent 10a4dde105
commit bc8ecf2aa7
2 changed files with 14 additions and 2 deletions

View File

@ -37,7 +37,13 @@ void CheckPostfixOperator::postfixOperator()
if (!_settings->_checkCodingStyle)
return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
const Token *tok = _tokenizer->tokens();
// prevent crash if first token is ++ or --
if (Token::Match(tok, "++|--"))
tok = tok->next();
for (; tok; tok = tok->next())
{
bool result = false;
if (Token::Match(tok, "++|--"))

View File

@ -67,6 +67,7 @@ private:
TEST_CASE(teststream);
TEST_CASE(testvolatile);
TEST_CASE(testiterator);
TEST_CASE(test2168);
}
void testsimple()
@ -364,7 +365,12 @@ private:
}
void test2168()
{
check("--> declare allocator lock here\n"
"int main(){}\n");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestPostfixOperator)