From e0c8118c027f2f95232dda2b1d67f37cb2a30934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 9 Apr 2020 17:42:51 +0200 Subject: [PATCH] Fixed crash in AST --- lib/tokenlist.cpp | 2 ++ test/testgarbage.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index ef86c5750..f442e7e2b 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1482,6 +1482,8 @@ static Token * createAstAtToken(Token *tok, bool cpp) decl = true; typetok = typetok->next(); } + if (!typetok) + return nullptr; if (decl && Token::Match(typetok->previous(), "[*&] %var% =")) tok = typetok; } diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 1f904de78..dbc84edd2 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -245,6 +245,7 @@ private: TEST_CASE(garbageCode211); // #8764 TEST_CASE(garbageCode212); // #8765 TEST_CASE(garbageCode213); // #8758 + TEST_CASE(garbageCode214); TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1 @@ -1666,6 +1667,10 @@ private: ASSERT_THROW(checkCode("{\"\"[(1||)];}"), InternalError); } + void garbageCode214() { + checkCode("THIS FILE CONTAINS VARIOUS TEXT"); + } + void syntaxErrorFirstToken() { ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818 ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858