From 0dc4b755656330cb357c4d44e6c385f5e97f820d Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sat, 23 Aug 2014 12:36:42 +0200 Subject: [PATCH] Fixed crash on invalid code #6080 --- lib/checkexceptionsafety.cpp | 2 +- test/testexceptionsafety.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index a768b5f6b..9f8fcc023 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -93,7 +93,7 @@ void CheckExceptionSafety::deallocThrow() tok = tok->next(); if (Token::simpleMatch(tok, "[ ]")) tok = tok->tokAt(2); - if (!tok) + if (!tok || tok == scope->classEnd) break; if (!Token::Match(tok, "%var% ;")) continue; diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index b4f09d59f..3ce134027 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -49,6 +49,8 @@ private: TEST_CASE(nothrowAttributeThrow); TEST_CASE(nothrowAttributeThrow2); // #5703 TEST_CASE(nothrowDeclspecThrow); + + TEST_CASE(garbage); } void check(const char code[], bool inconclusive = false) { @@ -411,6 +413,10 @@ private: check("const char *func() __attribute((nothrow)); void func1() { return 0; }\n"); ASSERT_EQUALS("", errout.str()); } + + void garbage() { + check("{ } A() { delete }"); // #6080 + } }; REGISTER_TEST(TestExceptionSafety)