Fixed #805 (False positive: Member functions not handled correctly)
This commit is contained in:
parent
b6999d010f
commit
ed3860a0a7
|
@ -523,6 +523,8 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
|
||||||
int par = 1;
|
int par = 1;
|
||||||
int parlevel = 0;
|
int parlevel = 0;
|
||||||
|
|
||||||
|
const bool dot(tok->previous()->str() == ".");
|
||||||
|
|
||||||
for (; tok; tok = tok->next())
|
for (; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (tok->str() == "(")
|
if (tok->str() == "(")
|
||||||
|
@ -542,6 +544,9 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
|
||||||
++par;
|
++par;
|
||||||
if (varid > 0 && Token::Match(tok, "[,()] %varid% [,()]", varid))
|
if (varid > 0 && Token::Match(tok, "[,()] %varid% [,()]", varid))
|
||||||
{
|
{
|
||||||
|
if (dot)
|
||||||
|
return "use";
|
||||||
|
|
||||||
const Token *ftok = _tokenizer->getFunctionTokenByName(funcname.c_str());
|
const Token *ftok = _tokenizer->getFunctionTokenByName(funcname.c_str());
|
||||||
if (!ftok)
|
if (!ftok)
|
||||||
return "use";
|
return "use";
|
||||||
|
|
|
@ -271,6 +271,8 @@ private:
|
||||||
// Unknown syntax
|
// Unknown syntax
|
||||||
TEST_CASE(unknownSyntax1);
|
TEST_CASE(unknownSyntax1);
|
||||||
TEST_CASE(knownFunctions);
|
TEST_CASE(knownFunctions);
|
||||||
|
|
||||||
|
TEST_CASE(same_function_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2393,6 +2395,18 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void same_function_name()
|
||||||
|
{
|
||||||
|
check("void a(char *p)\n"
|
||||||
|
"{ }\n"
|
||||||
|
"void b()\n"
|
||||||
|
"{\n"
|
||||||
|
" char *p = malloc(10);\n"
|
||||||
|
" abc.a(p);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static TestMemleakInFunction testMemleakInFunction;
|
static TestMemleakInFunction testMemleakInFunction;
|
||||||
|
|
Loading…
Reference in New Issue