memleak: strcat_result_assignment fixed by checking some functions for "x = func(x[),]".
This commit is contained in:
parent
7037a3b4f6
commit
9fb11bbfcc
|
@ -311,6 +311,15 @@ void CheckMemoryLeakClass::MemoryLeak(const Token *tok, const char varname[], Al
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CheckMemoryLeakClass::MatchFunctionsThatReturnArg(const Token *tok, const std::string varname)
|
||||
{
|
||||
return
|
||||
Token::Match(tok, std::string("; " + varname + " = strcat ( " + varname + " ,").c_str())
|
||||
|| Token::Match(tok, std::string("; " + varname + " = memcpy ( " + varname + " ,").c_str())
|
||||
|| Token::Match(tok, std::string("; " + varname + " = memmove ( " + varname + " ,").c_str())
|
||||
|| Token::Match(tok, std::string("; " + varname + " = strcpy ( " + varname + " ,").c_str());
|
||||
}
|
||||
|
||||
bool CheckMemoryLeakClass::notvar(const Token *tok, const char *varnames[])
|
||||
{
|
||||
std::string varname;
|
||||
|
@ -422,6 +431,11 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
|||
alloctype = alloc;
|
||||
}
|
||||
|
||||
else if (MatchFunctionsThatReturnArg(tok, std::string(varname)))
|
||||
{
|
||||
addtoken("use");
|
||||
}
|
||||
|
||||
// assignment..
|
||||
else
|
||||
{
|
||||
|
|
|
@ -90,6 +90,7 @@ private:
|
|||
*/
|
||||
Token *getcode(const Token *tok, std::list<const Token *> callstack, const char varname[], AllocType &alloctype, AllocType &dealloctype, bool classmember);
|
||||
bool notvar(const Token *tok, const char *varnames[]);
|
||||
bool MatchFunctionsThatReturnArg(const Token *tok, const std::string varname);
|
||||
void MemoryLeak(const Token *tok, const char varname[], AllocType alloctype);
|
||||
void MismatchError(const Token *Tok1, const std::list<const Token *> &callstack, const char varname[]);
|
||||
const char * call_func(const Token *tok, std::list<const Token *> callstack, const char *varnames[], AllocType &alloctype, AllocType &dealloctype);
|
||||
|
|
|
@ -173,7 +173,7 @@ private:
|
|||
// free a free'd pointer
|
||||
TEST_CASE(freefree1);
|
||||
TEST_CASE(freefree2);
|
||||
// TODO TEST_CASE(strcat_result_assignment);
|
||||
TEST_CASE(strcat_result_assignment);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue