From 4e1ce93104efb01f9588c13e1eac8d754784b8f3 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 21 Feb 2011 19:30:40 -0500 Subject: [PATCH] fix #2600 (segmentation fault of cppcheck ( enum{const} )) --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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);"));