Fixed #511 (false positive, memory leak when using 'var = ({});')
This commit is contained in:
parent
f11d34c109
commit
b7ffcf53ba
|
@ -1647,6 +1647,15 @@ void CheckMemoryLeakInFunction::check()
|
|||
else if (tok->str() == "}")
|
||||
--indentlevel;
|
||||
|
||||
// Skip these weird blocks... "( { ... } )"
|
||||
else if (Token::simpleMatch(tok, "( {"))
|
||||
{
|
||||
tok = tok->link();
|
||||
if (!tok)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
// In function..
|
||||
if (indentlevel == 0)
|
||||
{
|
||||
|
|
|
@ -287,6 +287,9 @@ private:
|
|||
|
||||
TEST_CASE(pointer_to_pointer);
|
||||
TEST_CASE(dealloc_and_alloc_in_func);
|
||||
|
||||
// Unknown syntax
|
||||
TEST_CASE(unknownSyntax1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2452,6 +2455,25 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void unknownSyntax1()
|
||||
{
|
||||
// I don't know what this syntax means so cppcheck should bail out
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
" void *sym = ( {\n"
|
||||
" void *__ptr = malloc(100);\n"
|
||||
" if(!__ptr && 100 != 0)\n"
|
||||
" {\n"
|
||||
" exit(1);\n"
|
||||
" }\n"
|
||||
" __ptr;\n"
|
||||
" } );\n"
|
||||
" free(sym);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
static TestMemleakInFunction testMemleakInFunction;
|
||||
|
|
Loading…
Reference in New Issue