From 56ae77ba87cb528372daf385f865230b938d2ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 8 Feb 2011 20:18:15 +0100 Subject: [PATCH] Fixed #2555 (Cppcheck 1.47 - Crash on WinMerge-Trunk (Win7 x64)) --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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() {