Fixed #5659 (False negative: mismatching allocation / deallocation whith using namespace)
This commit is contained in:
parent
ab2f8bfba3
commit
7eb3988415
|
@ -3038,7 +3038,18 @@ const Scope * SymbolDatabase::findNamespace(const Token * tok, const Scope * sco
|
||||||
|
|
||||||
Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *ns)
|
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) {
|
if (!function) {
|
||||||
const Scope * scope = ns->findRecordInNestedList(func->str());
|
const Scope * scope = ns->findRecordInNestedList(func->str());
|
||||||
|
|
|
@ -5442,6 +5442,29 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:16]: (warning) Possible leak in public function. The pointer 'data_' is not deallocated before it is allocated.\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());
|
"[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() {
|
void func1() {
|
||||||
|
|
Loading…
Reference in New Issue