Fixed #2518 (Crash when checking rockbox's firmwire)

This commit is contained in:
Daniel Marjamäki 2011-01-27 21:16:25 +01:00
parent 524498e439
commit 88abeeebba
2 changed files with 20 additions and 0 deletions

View File

@ -2041,6 +2041,16 @@ bool Tokenizer::tokenize(std::istream &code,
}
}
// if MACRO
for (const Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "if|for|while %var% ("))
{
syntaxError(tok);
return false;
}
}
// Simplify JAVA/C# code
if (isJavaOrCSharp() && _files[0].find(".java") != std::string::npos)
{

View File

@ -52,6 +52,7 @@ private:
// don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax);
TEST_CASE(wrong_syntax_if_macro); // #2518 - if MACRO()
TEST_CASE(minus);
@ -522,6 +523,15 @@ private:
}
}
void wrong_syntax_if_macro()
{
// #2518
errout.str("");
const std::string code("void f() { if MACRO(); }");
tokenizeAndStringify(code.c_str(), false);
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
}
void minus()
{
ASSERT_EQUALS("i = -12", tokenizeAndStringify("i = -12"));