diff --git a/lib/checkother.cpp b/lib/checkother.cpp index e46f7c4dc..71d87c7ee 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2192,6 +2192,8 @@ void CheckOther::checkZeroDivisionOrUselessCondition() ftok = ftok ? ftok->previous() : NULL; } ftok = ftok ? ftok->previous() : NULL; + if (!ftok) + continue; if (!Token::Match(ftok, "%var% (") && ftok->function()) continue; diff --git a/test/testother.cpp b/test/testother.cpp index 9afca01fd..0a82c6567 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -508,6 +508,15 @@ private: " while (y || x == 0) { x--; }\n" "}"); ASSERT_EQUALS("", errout.str()); + + // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition + check("void f() {\n" + "double* p1= new double[1];\n" + "double* p2= new double[1];\n" + "double* p3= new double[1];\n" + "double* pp[3] = {p1,p2,p3};\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void nanInArithmeticExpression() {