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:
parent
10f6678cf9
commit
769119c725
|
@ -629,6 +629,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
||||||
addtoken("realloc");
|
addtoken("realloc");
|
||||||
addtoken(";");
|
addtoken(";");
|
||||||
realloc = true;
|
realloc = true;
|
||||||
|
tok = tok->tokAt(2);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,8 +938,25 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
||||||
{
|
{
|
||||||
const char *str = call_func(tok, callstack, varnames, alloctype, dealloctype, all, sz);
|
const char *str = call_func(tok, callstack, varnames, alloctype, dealloctype, all, sz);
|
||||||
if (str)
|
if (str)
|
||||||
|
{
|
||||||
addtoken(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback..
|
// Callback..
|
||||||
|
@ -1495,7 +1514,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const char varname
|
||||||
const Token *result;
|
const Token *result;
|
||||||
|
|
||||||
Token *tok = getcode(Tok1, callstack, varname, alloctype, dealloctype, classmember, all, sz);
|
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..
|
// Simplify the code and check if freed memory is used..
|
||||||
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||||
|
|
|
@ -1677,7 +1677,7 @@ private:
|
||||||
" free(new_buf);\n"
|
" free(new_buf);\n"
|
||||||
"}\n", true);
|
"}\n", true);
|
||||||
|
|
||||||
TODO_ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void assign()
|
void assign()
|
||||||
|
|
Loading…
Reference in New Issue