From bd2892fde480ddd164151cfd533ab9691ab259c6 Mon Sep 17 00:00:00 2001 From: amai2012 Date: Fri, 8 Jan 2016 11:59:02 +0100 Subject: [PATCH] Ticket #7270 segmentation fault (invalid code) in Tokenizer::simplifyLabelsCaseDefault. include fix for cygwin --- lib/tokenize.cpp | 2 ++ test/testgarbage.cpp | 6 ++++++ test/testsuite.cpp | 1 + 3 files changed, 9 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f43803bec..d431f1911 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2309,6 +2309,8 @@ void Tokenizer::simplifyLabelsCaseDefault() break; if (tok->str() != "case" && tok->next() && tok->next()->str() == ":") { tok = tok->next(); + if (!tok->next()) + syntaxError(tok); // #7270 invalid code if (tok->next()->str() != ";" && tok->next()->str() != "case") tok->insertToken(";"); else diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 85df96cac..74f1ffe4b 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -219,6 +219,7 @@ private: TEST_CASE(garbageCode168); // #7246 TEST_CASE(garbageCode169); // #6731 TEST_CASE(garbageCode170); + TEST_CASE(garbageCode171); TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageAST); @@ -1441,6 +1442,11 @@ private: // 7255 checkCode("d i(){{f*s=typeid(()0,)}}", false); } + + void garbageCode171() { + // 7270 + ASSERT_THROW(checkCode("(){case()?():}:", false), InternalError); + } }; diff --git a/test/testsuite.cpp b/test/testsuite.cpp index d206c2517..6009f69c8 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -20,6 +20,7 @@ #include "options.h" #include "redirect.h" +#include #include #include