Fixed #5659 (False negative: mismatching allocation / deallocation whith using namespace)

This commit is contained in:
Robert Reif 2014-04-11 05:40:37 +02:00 committed by Daniel Marjamäki
parent ab2f8bfba3
commit 7eb3988415
2 changed files with 35 additions and 1 deletions

View File

@ -3038,7 +3038,18 @@ const Scope * SymbolDatabase::findNamespace(const Token * tok, const Scope * sco
Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *ns)
{
const Function * function = ns->findFunction(func);
const Function * function = nullptr;
std::list<Function>::const_iterator it;
for (it = ns->functionList.begin(); it != ns->functionList.end(); ++it) {
if (it->name() == func->str()) {
if (Function::argsMatch(ns, func->tokAt(2), it->argDef->next(), "", 0)) {
function = &*it;
break;
}
}
}
if (!function) {
const Scope * scope = ns->findRecordInNestedList(func->str());

View File

@ -5442,6 +5442,29 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:16]: (warning) Possible leak in public function. The pointer 'data_' is not deallocated before it is allocated.\n"
"[test.cpp:18]: (error) Mismatching allocation and deallocation: Foo::data_\n", errout.str());
check("namespace NS\n"
"{\n"
"class Foo\n"
"{\n"
"public:\n"
" void fct(int i);\n"
"\n"
"private:\n"
" char* data_;\n"
"};\n"
"}\n"
"\n"
"using namespace NS;\n"
"\n"
"void Foo::fct(int i)\n"
"{\n"
" data_ = new char[42];\n"
" delete data_;\n"
" data_ = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:16]: (warning) Possible leak in public function. The pointer 'data_' is not deallocated before it is allocated.\n"
"[test.cpp:18]: (error) Mismatching allocation and deallocation: Foo::data_\n", errout.str());
}
void func1() {