From defee734f59259f1d57b5ca75a8633b03092aa3c Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Mon, 20 Jul 2015 19:04:34 +0200 Subject: [PATCH] #6846 segmentation fault (invalid code) in CheckClass::hasAssignSelf --- lib/checkclass.cpp | 2 ++ test/testgarbage.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index d32a91b98..ec9ae85bf 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1424,6 +1424,8 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope) const bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs) { + if (!rhs) + return false; const Token *last = func->functionScope->classEnd; for (const Token *tok = func->functionScope->classStart; tok && tok != last; tok = tok->next()) { if (Token::simpleMatch(tok, "if (")) { diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 4d5af8b88..fba9c56f1 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -141,6 +141,7 @@ private: TEST_CASE(garbageCode99); TEST_CASE(garbageCode100); TEST_CASE(garbageCode101); // #6835 + TEST_CASE(garbageCode102); // #6846 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -799,6 +800,10 @@ private: checkCode("template < class =( , ) X = 1> struct A {}; A a;"); } + void garbageCode102() { // #6846 + checkCode("struct Object { ( ) ; Object & operator= ( Object ) { ( ) { } if ( this != & b ) } }"); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"