Memory leaks: Fixed two todo testcases (getcode handling of asprintf)

This commit is contained in:
Daniel Marjamäki 2009-08-29 07:02:36 +02:00
parent ab047c680c
commit 406fdd3219
2 changed files with 15 additions and 4 deletions

View File

@ -627,9 +627,20 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
if (parlevel == 0 && tok->str() == ";")
addtoken(";");
if (varid && Token::Match(tok->previous(), "[(;{}] %varid% =", varid))
if (Token::Match(tok->previous(), "[(;{}] %varid% =", varid) ||
Token::Match(tok, "asprintf ( & %varid% ,", varid))
{
AllocType alloc = getAllocationType(tok->tokAt(2), varid);
AllocType alloc;
if (Token::simpleMatch(tok, "asprintf ("))
{
alloc = Malloc;
tok = tok->next()->link();
}
else
{
alloc = getAllocationType(tok->tokAt(2), varid);
}
bool realloc = false;
if (sz > 1 &&

View File

@ -351,8 +351,8 @@ private:
ASSERT_EQUALS(";;do{}loop;", getcode("char *s; do { } while (a);", "s"));
// asprintf..
TODO_ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"xyz\");", "s"));
TODO_ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"s: %s\", s);", "s"));
ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"xyz\");", "s"));
ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"s: %s\", s);", "s"));
ASSERT_EQUALS(";;;", getcode("char *s; asprintf(&p, \"s: %s\", s);", "s"));
// use..