From 26f244e6389f5fa18d6656e3093c33278d3251d1 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sun, 24 May 2015 08:16:34 +0200 Subject: [PATCH] Ticket #6704: Tighten pattern skipping base class declarations and fix crash upon garbage code. --- lib/tokenize.cpp | 2 +- test/testgarbage.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 345523e00..54611be9e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2792,7 +2792,7 @@ void Tokenizer::setVarId() const Token* tokStart = tok->tokAt(2); while (tokStart && tokStart->str() != "{") { - if (Token::Match(tokStart, "public|private|protected")) + if (Token::Match(tokStart, "public|private|protected %name%")) tokStart = tokStart->next(); if (tokStart->strAt(1) == "," || tokStart->strAt(1) == "{") varlist[classname].insert(varlist[tokStart->str()].begin(), varlist[tokStart->str()].end()); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 6ea33889c..2782ae82c 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -82,6 +82,7 @@ private: TEST_CASE(garbageCode41); // #6685 TEST_CASE(garbageCode42); // #5760 TEST_CASE(garbageCode43); // #6703 + TEST_CASE(garbageCode44); // #6704 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -475,6 +476,10 @@ private: checkCode("int { }; struct A a = { }"); } + void garbageCode44() { // #6704 + ASSERT_THROW(checkCode("{ { }; }; { class A : }; public typedef b;"), InternalError); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"