Fix simplifyTypedef crash on lambda. (#1054)

This commit is contained in:
IOBYTE 2018-01-24 09:04:33 -05:00 committed by amai2012
parent 0f561d0ed6
commit 558e0757c2
2 changed files with 10 additions and 1 deletions

View File

@ -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;

View File

@ -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"