diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a458bcf49..257f0c3a7 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1550,7 +1550,10 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s const Token* endTok = NULL; const Token* nameTok = NULL; - while (tok->str() != "," && tok->str() != ")" && tok->str() != "=") { + if (tok->str() == "," || tok->str() == ")") + return; // Syntax error + + do { if (tok->varId() != 0) { nameTok = tok; endTok = tok->previous(); @@ -1569,7 +1572,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s if (!tok) // something is wrong so just bail return; - } + } while (tok->str() != "," && tok->str() != ")" && tok->str() != "="); const Token *typeTok = startTok->tokAt(startTok->str() == "const" ? 1 : 0); if (typeTok->str() == "struct") diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index e8c69bd57..01c94b3a9 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -109,6 +109,7 @@ private: TEST_CASE(functionArgs1); TEST_CASE(functionArgs2); + TEST_CASE(functionArgs3); TEST_CASE(namespaces1); TEST_CASE(namespaces2); @@ -786,6 +787,12 @@ private: ASSERT_EQUALS(4UL, a->dimension(1)); } + void functionArgs3() { + GET_SYMBOL_DB("void f(int i,) { }"); // Don't crash + const Variable *a = db->getVariableFromVarId(1); + ASSERT_EQUALS("i", a->nameToken()->str()); + } + void namespaces1() { GET_SYMBOL_DB("namespace fred {\n" " namespace barney {\n"