diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c52059dd5..bc294e187 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7845,7 +7845,7 @@ void Tokenizer::simplifyEnum() } // check for a variable definition: enum {} x; - if (end->next()->str() != ";") + if (end->next() && end->next()->str() != ";") { Token *tempTok = end; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index e883f6adb..abad36601 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -285,6 +285,7 @@ private: TEST_CASE(enum17); // ticket #2381 (duplicate enums) TEST_CASE(enum18); // #2466 (array with same name as enum constant) TEST_CASE(enum19); // ticket #2536 + TEST_CASE(enum20); // ticket #2600 // remove "std::" on some standard functions TEST_CASE(removestd); @@ -6183,6 +6184,12 @@ private: ASSERT_EQUALS(";", tok(code, false)); } + void enum20() // ticket #2600 segmentation fault + { + const char code[] = "enum { const }\n"; + ASSERT_EQUALS(";", tok(code, false)); + } + void removestd() { ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));