Fixed #3041 (false positive reported for error with id='deallocuse')
This commit is contained in:
parent
2123f6fafc
commit
2f0fc9444f
|
@ -697,7 +697,14 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
|
|||
if (tok2->str() == "(" || tok2->str() == ")")
|
||||
break;
|
||||
if (tok2->varId() == varid)
|
||||
return (tok->strAt(-1)==".") ? "use" : "use_";
|
||||
{
|
||||
if (tok->strAt(-1) == ".")
|
||||
return "use";
|
||||
else if (tok2->strAt(1) == "=")
|
||||
return "assign";
|
||||
else
|
||||
return"use_";
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -276,6 +276,7 @@ private:
|
|||
// * It is ok to take the address to deallocated memory
|
||||
// * It is not ok to dereference a pointer to deallocated memory
|
||||
TEST_CASE(dealloc_use);
|
||||
TEST_CASE(dealloc_use_2);
|
||||
|
||||
// free a free'd pointer
|
||||
TEST_CASE(freefree1);
|
||||
|
@ -2962,6 +2963,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void dealloc_use_2()
|
||||
{
|
||||
// #3041 - assigning pointer when it's used
|
||||
check("void f(char *s) {\n"
|
||||
" free(s);\n"
|
||||
" strcpy(a, s=b());\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void freefree1()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue