Tokenizer: Bailout if @ is encountered in the code

This commit is contained in:
Daniel Marjamäki 2010-12-26 15:07:14 +01:00
parent 3020e77570
commit f4581d833d
2 changed files with 23 additions and 0 deletions

View File

@ -2169,6 +2169,18 @@ bool Tokenizer::tokenize(std::istream &code,
// Remove __asm..
simplifyAsm();
// When the assembly code has been cleaned up, no @ is allowed
for (const Token *tok = _tokens; tok; tok = tok->next())
{
if (tok->str() == "(")
tok = tok->link();
else if (tok->str()[0] == '@')
{
deallocateTokens();
return false;
}
}
// Remove "volatile", "inline", "register", and "restrict"
simplifyKeyword();

View File

@ -50,6 +50,7 @@ private:
TEST_CASE(tokenize10);
TEST_CASE(tokenize11);
TEST_CASE(tokenize12);
TEST_CASE(tokenize13); // bailout if the code contains "@" - that is not handled well.
// don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax);
@ -469,6 +470,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
// bailout if there is "@" - it is not handled well
void tokenize13()
{
const char code[] = "@implementation\n"
"-(Foo *)foo: (Bar *)bar\n"
"{ }\n"
"@end\n";
ASSERT_EQUALS("", tokenizeAndStringify(code));
}
void wrong_syntax()
{
{