Fixed #2873 (segmentation fault of cppcheck while scanning rose-compiler suite)

This commit is contained in:
Daniel Marjamäki 2011-07-16 19:26:11 +02:00
parent 597733bec4
commit cf3ab649fb
2 changed files with 10 additions and 1 deletions

View File

@ -4962,7 +4962,7 @@ bool Tokenizer::simplifyIfAddBraces()
{ {
for (Token *tok = _tokens; tok; tok = tok ? tok->next() : NULL) for (Token *tok = _tokens; tok; tok = tok ? tok->next() : NULL)
{ {
if (tok->str() == "(") if (tok->str() == "(" && !Token::Match(tok->previous(), "[;{}]"))
{ {
tok = tok->link(); tok = tok->link();
continue; continue;

View File

@ -5705,6 +5705,15 @@ private:
{ {
tokenizeAndStringify("if()x"); tokenizeAndStringify("if()x");
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
// ticket #2873
{
const char code[] = "void f() { "
"( { if(*p) (*p) = x(); } ) "
"}";
ASSERT_EQUALS("void f ( ) { ( { if ( * p ) { ( * p ) = x ( ) ; } } ) }",
tokenizeAndStringify(code));
}
} }
}; };