* Add test cases for #10381, #10382 * Fix #7622 * Format
This commit is contained in:
parent
396a69a630
commit
d565cde815
|
@ -859,10 +859,17 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
|
|||
int argNr = 1;
|
||||
for (const Token *funcArg = tokFirstArg; funcArg; funcArg = funcArg->nextArgument()) {
|
||||
const Token* arg = funcArg;
|
||||
if (mTokenizer->isCPP() && arg->str() == "new") {
|
||||
arg = arg->next();
|
||||
if (Token::simpleMatch(arg, "( std :: nothrow )"))
|
||||
arg = arg->tokAt(5);
|
||||
if (mTokenizer->isCPP()) {
|
||||
int tokAdvance = 0;
|
||||
if (arg->str() == "new")
|
||||
tokAdvance = 1;
|
||||
else if (Token::simpleMatch(arg, "* new"))
|
||||
tokAdvance = 2;
|
||||
if (tokAdvance > 0) {
|
||||
arg = arg->tokAt(tokAdvance);
|
||||
if (Token::simpleMatch(arg, "( std :: nothrow )"))
|
||||
arg = arg->tokAt(5);
|
||||
}
|
||||
}
|
||||
|
||||
// Skip casts
|
||||
|
|
|
@ -471,6 +471,12 @@ private:
|
|||
" TestType *tt = new TestType();\n"
|
||||
"}", true);
|
||||
ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: tt\n", errout.str());
|
||||
|
||||
check("void f(Bar& b) {\n" // #7622
|
||||
" char* data = new char[10];\n"
|
||||
" b = Bar(*new Foo(data));\n"
|
||||
"}", /*cpp*/ true);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (information) --check-library: Function Foo() should have <use>/<leak-ignore> configuration\n", errout.str());
|
||||
}
|
||||
|
||||
void realloc1() {
|
||||
|
|
|
@ -1685,6 +1685,7 @@ private:
|
|||
TEST_CASE(function2); // #2848: Taking address in function
|
||||
TEST_CASE(function3); // #3024: kernel list
|
||||
TEST_CASE(function4); // #3038: Deallocating in function
|
||||
TEST_CASE(function5); // #10381, #10382
|
||||
|
||||
// Handle if-else
|
||||
TEST_CASE(ifelse);
|
||||
|
@ -1920,6 +1921,22 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void function5() {
|
||||
check("struct s f() {\n" // #10381
|
||||
" struct s s1;\n"
|
||||
" s1->x = malloc(1);\n"
|
||||
" return (s1);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct nc_rpc nc_rpc_getconfig() {\n" // #13082
|
||||
" struct nc_rpc rpc;\n"
|
||||
" rpc->filter = malloc(1);\n"
|
||||
" return (nc_rpc)rpc;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void ifelse() {
|
||||
check("static void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue