Improved handling of syntax errors in Tokenizer::simplifyAddBracesPair.

This commit is contained in:
Simon Martin 2013-06-29 14:05:49 +02:00
parent 6b2bab535b
commit e2deb59f8a
2 changed files with 7 additions and 0 deletions

View File

@ -4119,6 +4119,8 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
tokBracesEnd=tokAfterCondition->link();
} else {
Token * tokEnd = simplifyAddBracesToCommand(tokAfterCondition);
if (!tokEnd) // Ticket #4887
return tok;
if (tokEnd->str()!="}") {
// Token does not end with brace
// Look for ; to add own closing brace after it

View File

@ -72,6 +72,7 @@ private:
TEST_CASE(garbageCode1);
TEST_CASE(garbageCode2); // #4300
TEST_CASE(garbageCode3); // #4869
TEST_CASE(garbageCode4); // #4887
TEST_CASE(simplifyFileAndLineMacro); // tokenize "return - __LINE__;"
@ -912,6 +913,10 @@ private:
tokenizeAndStringify("enum { D = 2 s ; struct y { x } ; } { s.a = C ; s.b = D ; }");
}
void garbageCode4() { // #4887
tokenizeAndStringify("void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; }");
}
void simplifyFileAndLineMacro() { // tokenize 'return - __LINE__' correctly
ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;"));
}