diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ed76477ee..346405b8f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8748,7 +8748,7 @@ void Tokenizer::simplifyStructDecl() } // unnamed anonymous struct/union so remove it - else if (tok->next()->str() == ";") + else if (tok->next() && tok->next()->str() == ";") { if (tok1->str() == "union") { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 902b4567f..b79b99f58 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -304,7 +304,8 @@ private: TEST_CASE(initstruct); // struct ABC { } abc; => struct ABC { }; ABC abc; - TEST_CASE(simplifyStructDecl); + TEST_CASE(simplifyStructDecl1); + TEST_CASE(simplifyStructDecl2); // ticket #2579 // register int var; => int var; // inline int foo() {} => int foo() {} @@ -6222,7 +6223,7 @@ private: tok("; struct A a = { .buf = {0} };")); } - void simplifyStructDecl() + void simplifyStructDecl1() { { const char code[] = "struct ABC { } abc;"; @@ -6365,6 +6366,13 @@ private: } } + void simplifyStructDecl2() // ticket #2479 (segmentation fault) + { + const char code[] = "struct { char c; }"; + const char expected[] = "struct { char c ; }"; + ASSERT_EQUALS(expected, tok(code, false)); + } + void removeUnwantedKeywords() { ASSERT_EQUALS("int var ;", tok("register int var ;", true));