diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cdbd2edd6..aa646360d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8227,6 +8227,13 @@ void Tokenizer::simplifyEnum() if (tok->next()->str() == ":") { tok = tok->next(); + + if (!tok->next()) + { + syntaxError(tok); + return; + } + typeTokenStart = tok->next(); tok = tok->next(); typeTokenEnd = typeTokenStart; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 4789ae62c..c03d197d4 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -312,6 +312,7 @@ private: TEST_CASE(enum22); // ticket #2745 TEST_CASE(enum23); // ticket #2804 TEST_CASE(enum24); // ticket #2828 + TEST_CASE(enum25); // ticket #2966 // remove "std::" on some standard functions TEST_CASE(removestd); @@ -6648,6 +6649,13 @@ private: ASSERT_EQUALS("", errout.str()); } + void enum25() // ticket #2966 (segmentation fault) + { + const char code[] = "enum x :\n"; + tok(code, false); + ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); + } + void removestd() { ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));