From e3bbcf501f5dc32752f2144415f0d131e43bb190 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 6 Oct 2012 13:37:44 +0200 Subject: [PATCH] Fixed #4234 (segmentation fault of cppcheck in Tokenizer::simplifyFlowControl() (invalid code)) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ee20203f0..077ef5bdd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2400,7 +2400,7 @@ void Tokenizer::simplifyLabelsCaseDefault() if (Token::Match(tok, "[;{}] case")) { while (NULL != (tok = tok->next())) { - if (tok->str() == ":") + if (Token::Match(tok,"[:{};]")) break; } if (!tok) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index e51166604..542b59907 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5716,6 +5716,9 @@ private: //ticket #3227 ASSERT_EQUALS("void foo ( ) { switch ( n ) { label : ; case 1 : ; label1 : ; label2 : ; break ; } }", tokenizeAndStringify("void foo(){ switch (n){ label: case 1: label1: label2: break; }}")); + //ticket #4234 + ASSERT_EQUALS("( ) { switch break ; { switch ( x ) { case } y break ; : } }", + tokenizeAndStringify("( ) { switch break ; { switch ( x ) { case } y break ; : } }")); } void simplifyPointerToStandardType() {