diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 6fd61e395..7a6a800a3 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -364,7 +364,7 @@ void CheckOther::clarifyStatement() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { if (Token::Match(tok, "* %var%")) { const Token *tok2=tok->previous(); diff --git a/test/testother.cpp b/test/testother.cpp index a135c8c1f..6bb7a6b62 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4250,6 +4250,10 @@ private: " bar(**c++);\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #5166 segmentation fault (invalid code) in lib/checkother.cpp:329 ( void * f { } void b ( ) { * f } ) + check("void * f { } void b ( ) { * f }"); + ASSERT_EQUALS("", errout.str()); } // clarify conditions with = and comparison