From e2deb59f8aff11e8164a8e7d5c93c69e15ba0b15 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sat, 29 Jun 2013 14:05:49 +0200 Subject: [PATCH] Improved handling of syntax errors in Tokenizer::simplifyAddBracesPair. --- lib/tokenize.cpp | 2 ++ test/testtokenize.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0ca25240f..730f3f380 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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 diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1eb6557e1..49e148a84 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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__;")); }