From 15bb447fdc33a15fde0d100f25932dace6261a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 17 Jul 2014 08:44:55 +0200 Subject: [PATCH] Fixed #5965 (False positive zerodiv - loop iterating over double variable) --- lib/valueflow.cpp | 5 ++++- test/testvalueflow.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 9c601743c..1f8c5b003 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -943,8 +943,11 @@ static void execute(const Token *expr, if (!expr) *error = true; - else if (expr->isNumber()) + else if (expr->isNumber()) { *result = MathLib::toLongNumber(expr->str()); + if (MathLib::isFloat(expr->str())) + *error = true; + } else if (expr->varId() > 0) { const std::map::const_iterator var = programMemory->find(expr->varId()); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 6c38a44b9..0d50a5c28 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -939,6 +939,13 @@ private: " x;\n" "}"; ASSERT_EQUALS(true, testValueOfX(code, 4U, 0)); + + code = "void foo(double recoveredX) {\n" + " for (double x = 1e-18; x < 1e40; x *= 1.9) {\n" + " double relativeError = (x - recoveredX) / x;\n" + " }\n" + "}\n"; + ASSERT_EQUALS(false, testValueOfX(code, 3U, 0)); } void valueFlowSubFunction() {