diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 409381a25..4dd122d1a 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1250,7 +1250,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::liststr() == "else") || (tok->str() == "switch")) { addtoken(&rettail, tok, tok->str()); - if (tok->str() == "switch") + if (Token::simpleMatch(tok, "switch (")) tok = tok->next()->link(); continue; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 713179a00..4fbf3832b 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -197,6 +197,7 @@ private: TEST_CASE(switch2); TEST_CASE(switch3); + TEST_CASE(switch4); // #2555 - segfault TEST_CASE(ret5); // Bug 2458436 - return use TEST_CASE(ret6); @@ -1287,6 +1288,17 @@ private: ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: str\n", errout.str()); } + void switch4() + { + check("void f() {\n" + " switch MAKEWORD(1)\n" + " {\n" + " case 0:\n" + " return;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } void ret5() {