From 965d8f0ecccf123e6e0499825147b0146e4e30e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 21 Sep 2013 17:44:25 +0200 Subject: [PATCH] Fixed #5033 (segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition) --- lib/checkother.cpp | 2 ++ test/testother.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) 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() {