diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d06b51154..c2347a5c0 100755 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1045,8 +1045,10 @@ void Tokenizer::simplifyTypedef() // check for member functions else if (isCPP() && Token::Match(tok2, ")|] const| {")) { const Token *temp = tok2; - while (temp->str() == "]") + while (temp && temp->str() == "]" && temp->link() && temp->link()->previous()) temp = temp->link()->previous(); + if (!temp || !temp->link() || !temp->link()->previous()) + continue; const Token *func = temp->link()->previous(); if (temp->str() != ")") continue; diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index c40d9844b..4ce1c21f2 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -159,6 +159,7 @@ private: TEST_CASE(simplifyTypedef119); // ticket #7541 TEST_CASE(simplifyTypedef120); // ticket #8357 TEST_CASE(simplifyTypedef121); // ticket #5766 + TEST_CASE(simplifyTypedef122); // segmentation fault TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -2492,6 +2493,12 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef122() { // segmentation fault + const char code[] = "int result = [] { return git_run_cmd(\"update-index\",\"update-index -q --refresh\"); }();"; + tok(code); + ASSERT_EQUALS("", errout.str()); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n"