Fixed #1015 (SIGABRT: Tokenizer::validate for openttd/src/ai/ai_config.cpp)

This commit is contained in:
Daniel Marjamäki 2009-11-27 17:32:53 +01:00
parent 7616246597
commit c94ecfe1a3
2 changed files with 17 additions and 5 deletions

View File

@ -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;
}

View File

@ -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]"));