Fix #701 (false positive: Invalid deallocation)

http://sourceforge.net/apps/trac/cppcheck/ticket/701
This commit is contained in:
Reijo Tomperi 2009-09-20 23:38:32 +03:00
parent 1c01dd64f3
commit 0fff5a23bf
2 changed files with 17 additions and 11 deletions

View File

@ -1353,6 +1353,11 @@ void Tokenizer::simplifySizeof()
{
if (Token::Match(tempToken, "%var%"))
{
while (tempToken->next()->str() == "[")
{
tempToken = tempToken->next()->link();
}
if (tempToken->next()->str() == ".")
{
// We are checking a class or struct, search next varname
@ -1371,19 +1376,12 @@ void Tokenizer::simplifySizeof()
// nothing after this
tempToken = tempToken->tokAt(2);
}
else if (tempToken->next()->str() == "[")
{
/** @todo We need to find closing ], then check for
* dots and arrows "var[some[0]]->other" */
// But for now, just bail out
break;
}
// Ok, we should be clean. Add ) after tempToken
tok->insertToken("(");
tempToken->insertToken(")");
Token::createMutualLinks(tok->next(), tempToken->next());
setVarId();
break;
}
}

View File

@ -554,9 +554,17 @@ private:
void sizeof4()
{
const char code[] = "int i[10];\n"
"sizeof(i[0]);\n";
ASSERT_EQUALS("int i [ 10 ] ; 4 ;", sizeof_(code));
{
const char code[] = "int i[10];\n"
"sizeof(i[0]);\n";
ASSERT_EQUALS("int i [ 10 ] ; 4 ;", sizeof_(code));
}
{
const char code[] = "int i[10];\n"
"sizeof i[0];\n";
ASSERT_EQUALS("int i [ 10 ] ; 4 ;", sizeof_(code));
}
}
void sizeof5()