From 47531dd99c6bac74609cfaa5cebad87f04dfa7e8 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 15 Mar 2011 22:33:14 -0400 Subject: [PATCH] fix #2637 (segmentation fault of cppcheck ( {} const const )) --- lib/symboldatabase.cpp | 5 ++++- test/testclass.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a7edd4e41..f7574c63b 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1467,6 +1467,9 @@ void Scope::getVariableList() continue; tok = checkVariable(tok, varaccess); + + if (!tok) + break; } } @@ -1515,7 +1518,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess) bool isArray = false; - if (isVariableDeclaration(tok, vartok, typetok, isArray)) + if (tok && isVariableDeclaration(tok, vartok, typetok, isArray)) { isClass = (!typetok->isStandardType() && vartok->previous()->str() != "*"); tok = vartok->next(); diff --git a/test/testclass.cpp b/test/testclass.cpp index 45a9f22a7..7147ebee5 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -196,6 +196,7 @@ private: TEST_CASE(symboldatabase13); // ticket #2577 TEST_CASE(symboldatabase14); // ticket #2589 TEST_CASE(symboldatabase15); // ticket #2591 + TEST_CASE(symboldatabase16); // ticket #2637 } // Check the operator Equal @@ -5791,6 +5792,14 @@ private: ASSERT_EQUALS("", errout.str()); } + void symboldatabase16() + { + // ticket #2637 - segmentation fault + checkConst("{} const const\n"); + + ASSERT_EQUALS("", errout.str()); + } + }; REGISTER_TEST(TestClass)