Fixed #1020 (lib/tokenize.cpp:4615: bool Tokenizer::validate() const: Assertion 0 failed)

This commit is contained in:
Daniel Marjamäki 2009-11-29 12:14:42 +01:00
parent 57aac9270a
commit e7d7507c65
2 changed files with 26 additions and 2 deletions

View File

@ -1730,8 +1730,15 @@ void Tokenizer::simplifySizeof()
continue;
}
// sizeof * (...) -> sizeof(*...)
if (Token::simpleMatch(tok->next(), "* (") && !Token::simpleMatch(tok->tokAt(2)->link(), ") ."))
{
tok->deleteNext();
tok->next()->insertToken("*");
}
// sizeof int -> sizeof( int )
if (tok->strAt(1) != std::string("("))
if (tok->next()->str() != "(")
{
// Add parenthesis around the sizeof
for (Token *tempToken = tok->next(); tempToken; tempToken = tempToken->next())

View File

@ -70,6 +70,7 @@ private:
TEST_CASE(sizeof12);
TEST_CASE(sizeof13);
TEST_CASE(sizeof14);
TEST_CASE(sizeof15);
TEST_CASE(casting);
TEST_CASE(strlen1);
@ -148,9 +149,14 @@ private:
std::string tok(const char code[], bool simplify = true)
{
errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
Tokenizer tokenizer;
tokenizer.tokenize(istr, "test.cpp");
if (simplify)
tokenizer.simplifyTokenList();
@ -908,6 +914,17 @@ private:
ASSERT_EQUALS(expected, tok(code));
}
void sizeof15()
{
// ticket #1020
tok("void f()\n"
"{\n"
" int *n;\n"
" sizeof *(n);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void casting()
{
{