From 87767fb666833b0cef2bab3d34c70d334ae57c67 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sat, 26 Dec 2015 00:21:56 +0100 Subject: [PATCH] #7228 segmentation fault (invalid code) in Tokenizer::isFunctionHead --- lib/tokenize.cpp | 2 ++ test/testgarbage.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 04cdb3567..ef9090500 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -54,6 +54,8 @@ namespace { const Token * Tokenizer::isFunctionHead(const Token *tok, const std::string &endsWith) const { + if (!tok) + return nullptr; if (tok->str() == "(") tok = tok->link(); if (Token::Match(tok, ") const| [;:{]")) { diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 7cb36c6d5..38284355a 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -211,6 +211,7 @@ private: TEST_CASE(garbageCode160); // #7190 TEST_CASE(garbageCode161); // #7200 TEST_CASE(garbageCode162); // #7208 + TEST_CASE(garbageCode163); // #7228 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageAST); @@ -1392,6 +1393,11 @@ private: //7208 ASSERT_THROW(checkCode("return << >> x return << >> x ", false), InternalError); } + + void garbageCode163() { + //7228 + ASSERT_THROW(checkCode("typedef s f[](){typedef d h(;f)}", false), InternalError); + } };