From 835c234e183ca723091047745c0b010d482b157c Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sat, 14 Nov 2015 21:22:53 +0100 Subject: [PATCH] #7131 crash: Tokenizer::setVarId() --- lib/tokenize.cpp | 2 ++ test/testgarbage.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ca6c63f22..5dbf7899f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2886,6 +2886,8 @@ void Tokenizer::setVarId() do { tok3 = tok3->tokAt(2); } while (Token::Match(tok3, ":: %name%")); + if (!tok3) + syntaxError(tok2); const std::string& str3 = tok3->str(); if (str3 == "(") allMemberFunctions.push_back(tok2); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 647d9e5ec..49f749c6f 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -205,6 +205,7 @@ private: TEST_CASE(garbageCode154); // #7112 TEST_CASE(garbageCode155); // #7118 TEST_CASE(garbageCode156); // #7120 + TEST_CASE(garbageCode157); // #7131 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -1232,6 +1233,14 @@ private: checkCode("struct {}a; d f() { c ? : } {}a.p"); } + void garbageCode157() { // #7131 + ASSERT_THROW(checkCode("namespace std {\n" + " template < typename >\n" + " void swap(); \n" + "}" + "template std::swap\n"), InternalError); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"