From 03b12c549469d37264cdad34c8434e35bd7534ea Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 25 Nov 2010 07:43:39 +0100 Subject: [PATCH] Fixed #2230 (segmentation fault of cppcheck) --- lib/symboldatabase.cpp | 13 +++++++++++-- test/testclass.cpp | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index ea5e46096..6f176ea9d 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -705,11 +705,20 @@ const Token *SymbolDatabase::initBaseInfo(SpaceInfo *info, const Token *tok) } base.name += tok2->str(); - base.spaceInfo = 0; + // don't add unhandled templates + if (tok2->next()->str() == "<") + { + while (tok2->str() != ">") + tok2 = tok2->next(); + } + // save pattern for base class name - info->derivedFrom.push_back(base); + else + { + info->derivedFrom.push_back(base); + } } tok2 = tok2->next(); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 7ebb646bb..e60e51c67 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -171,6 +171,7 @@ private: TEST_CASE(symboldatabase4); TEST_CASE(symboldatabase5); // ticket #2178 TEST_CASE(symboldatabase6); // ticket #2221 + TEST_CASE(symboldatabase7); // ticket #2230 } // Check the operator Equal @@ -4860,6 +4861,23 @@ private: "Y>1)>> x5;\n"); ASSERT_EQUALS("", errout.str()); } + + void symboldatabase7() + { + // ticket #2230 - segmentation fault + checkConst("template class E,class D> class C : E\n" + "{\n" + "public:\n" + " int f();\n" + "};\n" + "class E : C\n" + "{\n" + "public:\n" + " int f() { return C< ::D,int>::f(); }\n" + "};\n"); + + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestClass)