diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 15a726552..06af89f0e 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -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) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 65d43dd06..5cd785b5e 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -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;