Fixed #2024 (Internal Error on multiple append calls on same string object)

This commit is contained in:
Daniel Marjamäki 2010-09-06 21:34:51 +02:00
parent f36666572a
commit cfe694330f
2 changed files with 27 additions and 1 deletions

View File

@ -3541,8 +3541,13 @@ void Tokenizer::simplifySizeof()
else if (tok->next()->str() != "(")
{
// Add parenthesis around the sizeof
int parlevel = 0;
for (Token *tempToken = tok->next(); tempToken; tempToken = tempToken->next())
{
if (tempToken->str() == "(")
++parlevel;
else if (tempToken->str() == ")")
--parlevel;
if (Token::Match(tempToken, "%var%"))
{
while (tempToken->next()->str() == "[")
@ -3568,8 +3573,9 @@ void Tokenizer::simplifySizeof()
// nothing after this
tempToken = tempToken->tokAt(2);
}
else if (Token::simpleMatch(tempToken->next(), ") ."))
else if (parlevel > 0 && Token::simpleMatch(tempToken->next(), ") ."))
{
--parlevel;
tempToken = tempToken->tokAt(2);
continue;
}

View File

@ -82,6 +82,7 @@ private:
TEST_CASE(sizeof17);
TEST_CASE(sizeof18);
TEST_CASE(sizeof19); // #1891 - sizeof 'x'
TEST_CASE(sizeof20); // #2024 - sizeof a)
TEST_CASE(sizeofsizeof);
TEST_CASE(casting);
@ -1322,6 +1323,25 @@ private:
}
}
void sizeof20()
{
// ticket #2024 - sizeof a)
const char code[] = "struct struct_a {\n"
" char a[20];\n"
"};\n"
"\n"
"void foo() {\n"
" struct_a a;\n"
" append(sizeof a).append();\n"
"}\n";
ASSERT_EQUALS("struct struct_a { char a [ 20 ] ; } ; "
"void foo ( ) {"
" struct_a a ;"
" append ( 100 ) . append ( ) ; "
"}", tok(code));
}
void sizeofsizeof()
{
// ticket #1682