From c94ecfe1a34046dc6bd767bf123fe11051152397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 27 Nov 2009 17:32:53 +0100 Subject: [PATCH] Fixed #1015 (SIGABRT: Tokenizer::validate for openttd/src/ai/ai_config.cpp) --- lib/tokenize.cpp | 12 ++++++++---- test/testsimplifytokens.cpp | 10 +++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 822ee1c60..73b082552 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -408,7 +408,7 @@ void Tokenizer::simplifyTypedef() } } - const std::string pattern = className + " :: " + typeName; + const std::string pattern(className.empty() ? std::string("") : className + " :: " + typeName); int level = 0; bool inScope = true; @@ -431,7 +431,7 @@ void Tokenizer::simplifyTypedef() } else if (tok2->str() == "{") ++level; - else if (Token::Match(tok2, pattern.c_str())) + else if (!pattern.empty() && Token::Match(tok2, pattern.c_str())) { tok2->deleteNext(); tok2->deleteNext(); @@ -439,8 +439,12 @@ void Tokenizer::simplifyTypedef() } else if (inScope && !exitThisScope && tok2->str() == typeName) { - if (Token::Match(tok2->tokAt(-2), "!!typedef") && - Token::Match(tok2->tokAt(-3), "!!typedef")) + if (Token::simpleMatch(tok2->previous(), "::")) + { + // Don't replace this typename if it's preceded by "::" + } + else if (Token::Match(tok2->tokAt(-2), "!!typedef") && + Token::Match(tok2->tokAt(-3), "!!typedef")) { simplifyType = true; } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index aab0abaf9..e9355d443 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -136,8 +136,9 @@ private: TEST_CASE(simplifyTypedef4) TEST_CASE(simplifyTypedef5) TEST_CASE(simplifyTypedef6) + TEST_CASE(simplifyTypedef7); TEST_CASE(reverseArraySyntax) - TEST_CASE(simplify_numeric_condition); + TEST_CASE(simplify_numeric_condition) TEST_CASE(pointeralias); @@ -2138,6 +2139,13 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } + void simplifyTypedef7() + { + const char code[] = "typedef int abc ; " + "Fred :: abc f ;"; + ASSERT_EQUALS(code, tok(code, false)); + } + void reverseArraySyntax() { ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));