Fixed #3041 (false positive reported for error with id='deallocuse')

This commit is contained in:
Daniel Marjamäki 2011-08-23 23:18:47 +02:00
parent 2123f6fafc
commit 2f0fc9444f
2 changed files with 18 additions and 1 deletions

View File

@ -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;

View File

@ -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()
{