Fix ticket #258 (segmentation fault)

http://apps.sourceforge.net/trac/cppcheck/ticket/258
This commit is contained in:
Reijo Tomperi 2009-04-20 21:38:05 +03:00
parent ca8f25fced
commit 14eff64194
2 changed files with 13 additions and 3 deletions

View File

@ -452,9 +452,7 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
// Remove "volatile"
while (Token::simpleMatch(_tokens, "volatile"))
{
Token *tok = _tokens;
_tokens = _tokens->next();
delete tok;
_tokens->deleteThis();
}
for (Token *tok = _tokens; tok; tok = tok->next())
{

View File

@ -130,6 +130,7 @@ private:
TEST_CASE(vardecl1);
TEST_CASE(vardecl2);
TEST_CASE(volatile_variables);
}
@ -1413,6 +1414,17 @@ private:
ASSERT_EQUALS("void foo ( a , b ) unsigned int a ; unsigned int b ; { }", actual);
}
void volatile_variables()
{
const char code[] = "volatile int a=0;\n"
"volatile int b=0;\n"
"volatile int c=0;\n";
const std::string actual(tokenizeAndStringify(code));
ASSERT_EQUALS("int a ; a = 0 ;\nint b ; b = 0 ;\nint c ; c = 0 ;", actual);
}
};
REGISTER_TEST(TestTokenizer)