Fix ticket #552 (False positive with --all when realloc is used with two variables.)

http://sourceforge.net/apps/trac/cppcheck/ticket/552
This commit is contained in:
Reijo Tomperi 2009-08-02 23:30:43 +03:00
parent 10f6678cf9
commit 769119c725
2 changed files with 21 additions and 2 deletions

View File

@ -629,6 +629,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
addtoken("realloc");
addtoken(";");
realloc = true;
tok = tok->tokAt(2);
continue;
}
}
@ -936,7 +938,24 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
{
const char *str = call_func(tok, callstack, varnames, alloctype, dealloctype, all, sz);
if (str)
{
addtoken(str);
}
else
{
if (getReallocationType(tok) != No &&
Token::simpleMatch(tok->tokAt(2), varnameStr.c_str())
)
{
addtoken("if");
addtoken("{");
addtoken("dealloc");
addtoken(";");
addtoken("}");
tok = tok->tokAt(2);
continue;
}
}
}
}
@ -1495,7 +1514,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const char varname
const Token *result;
Token *tok = getcode(Tok1, callstack, varname, alloctype, dealloctype, classmember, all, sz);
//tok->printOut( "getcode result" );
//tok->printOut((std::string("Checkmemoryleak: getcode result for: ") + varname).c_str());
// Simplify the code and check if freed memory is used..
for (Token *tok2 = tok; tok2; tok2 = tok2->next())

View File

@ -1677,7 +1677,7 @@ private:
" free(new_buf);\n"
"}\n", true);
TODO_ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout.str());
}
void assign()