From 600641c4c51ab051fc0d5820213cf29b2c010b2f Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Wed, 14 Oct 2015 20:34:55 +0200 Subject: [PATCH] #7043 segmentation fault (invalid code) in Tokenizer::simplifyVarDecl --- lib/tokenize.cpp | 2 ++ test/testgarbage.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0f38f275f..cc02cb028 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5299,6 +5299,8 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_ tok = tok->link(); } + if (!tok) + syntaxError(nullptr); // #7043 invalid code if (tok->previous() && !Token::Match(tok->previous(), "{|}|;|)|public:|protected:|private:")) continue; diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index d77d32c31..9f344446a 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -190,6 +190,7 @@ private: TEST_CASE(garbageCode138); // #6660 TEST_CASE(garbageCode139); // #6659 TEST_CASE(garbageCode140); // #7035 + TEST_CASE(garbageCode141); // #7043 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -1109,6 +1110,10 @@ private: ASSERT_THROW(checkCode("int foo(int align) { int off(= 0 % align; return off) ? \\ align - off : 0; \\ }"), InternalError); } + void garbageCode141() { // #7043 + ASSERT_THROW(checkCode("enum { X = << { X } } enum { X = X } = X ;"), InternalError); + } + void garbageValueFlow() { // #6089