From 50a184c3e95c92e126bfc1a7c05be3e898106e85 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Thu, 27 Feb 2014 18:24:51 +0100 Subject: [PATCH] Fixed #5166 (segmentation fault (invalid code) in lib/checkother.cpp:329 ( void * f { } void b ( ) { * f } )) --- lib/checkother.cpp | 2 +- test/testother.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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