LeakAutoVar: Handle C++ casts in function calls (#5181)
This commit is contained in:
parent
353f54089c
commit
fe56b0c42a
|
@ -934,6 +934,8 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip casts
|
// Skip casts
|
||||||
|
if (arg->isKeyword() && arg->astParent() && arg->astParent()->isCast())
|
||||||
|
arg = arg->astParent();
|
||||||
while (arg && arg->isCast())
|
while (arg && arg->isCast())
|
||||||
arg = arg->astOperand2() ? arg->astOperand2() : arg->astOperand1();
|
arg = arg->astOperand2() ? arg->astOperand2() : arg->astOperand1();
|
||||||
const Token * const argTypeStartTok = arg;
|
const Token * const argTypeStartTok = arg;
|
||||||
|
|
|
@ -564,6 +564,13 @@ private:
|
||||||
" g();\n"
|
" g();\n"
|
||||||
"}\n", /*cpp*/ true);
|
"}\n", /*cpp*/ true);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void g() {}\n" // #10517
|
||||||
|
"void f() {\n"
|
||||||
|
" char* p = malloc(10);\n"
|
||||||
|
" g();\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.c:5]: (error) Memory leak: p\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void isAutoDealloc() {
|
void isAutoDealloc() {
|
||||||
|
@ -2751,6 +2758,20 @@ private:
|
||||||
" free_func((void *)(1), buf);\n"
|
" free_func((void *)(1), buf);\n"
|
||||||
"}", settingsFunctionCall);
|
"}", settingsFunctionCall);
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (information) --check-library: Function free_func() should have <use>/<leak-ignore> configuration\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (information) --check-library: Function free_func() should have <use>/<leak-ignore> configuration\n", errout.str());
|
||||||
|
|
||||||
|
check("void g(void*);\n"
|
||||||
|
"void h(int, void*);\n"
|
||||||
|
"void f1() {\n"
|
||||||
|
" int* p = new int;\n"
|
||||||
|
" g(static_cast<void*>(p));\n"
|
||||||
|
"}\n"
|
||||||
|
"void f2() {\n"
|
||||||
|
" int* p = new int;\n"
|
||||||
|
" h(1, static_cast<void*>(p));\n"
|
||||||
|
"}\n", /*cpp*/ true);
|
||||||
|
ASSERT_EQUALS("[test.cpp:6]: (information) --check-library: Function g() should have <use>/<leak-ignore> configuration\n"
|
||||||
|
"[test.cpp:10]: (information) --check-library: Function h() should have <use>/<leak-ignore> configuration\n",
|
||||||
|
errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void functionCallLeakIgnoreConfig() { // #7923
|
void functionCallLeakIgnoreConfig() { // #7923
|
||||||
|
|
Loading…
Reference in New Issue