From 0556edd151cb41543fd978950b6c6eac6dc9d0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 25 May 2016 13:14:34 +0200 Subject: [PATCH] fix #7505 (crash on invalid code) --- lib/symboldatabase.cpp | 2 +- test/testgarbage.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 6b9269d55..0b098370f 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3258,7 +3258,7 @@ const Token * Scope::addEnum(const Token * tok, bool isCpp) if (tok2 == end) { tok2 = tok2->next(); - if (tok2->str() != ";") + if (tok2 && tok2->str() != ";") tok2 = nullptr; } else tok2 = nullptr; diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index c5d7f8d32..5650c8c8e 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -231,6 +231,7 @@ private: TEST_CASE(garbageCode180); TEST_CASE(garbageCode181); TEST_CASE(garbageCode182); // #4195 + TEST_CASE(garbageCode183); // #7505 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageAST); @@ -1515,6 +1516,10 @@ private: void garbageCode182() { ASSERT_THROW(checkCode("enum { int f ( ) { return = } r = f ( ) ; }"), InternalError); } + // #7505 - segfault + void garbageCode183() { + ASSERT_THROW(checkCode("= { int } enum return { r = f() f(); }"), InternalError); + } };