From 9eaadc81e269cea8ecd591b996297fbfa30cb822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 28 Jun 2014 12:04:20 +0200 Subject: [PATCH] Fixed #5861 (valueFlowSubFunction: fp for float value) --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 167f6de48..3ade624d7 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1203,7 +1203,7 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger, // passing value(s) to function if (Token::Match(tok, "[(,] %var% [,)]") && !tok->next()->values.empty()) argvalues = tok->next()->values; - else if (Token::Match(tok, "[(,] %num% [,)]")) { + else if (Token::Match(tok, "[(,] %num% [,)]") && MathLib::isInt(tok->strAt(1))) { argvalues.clear(); argvalues.push_back(ValueFlow::Value(MathLib::toLongNumber(tok->next()->str()))); } else { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 352b56546..ac15c79f4 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -918,6 +918,13 @@ private: "void f2() { f1(0); }"; ASSERT_EQUALS(true, testValueOfX(code, 2U, 0)); ASSERT_EQUALS(false, testValueOfX(code, 3U, 0)); + + // #5861 - fp with float + code = "void f1(float x) {\n" + " return 1.0 / x;\n" + "}\n" + "void f2() { f1(0.5); }"; + ASSERT_EQUALS(false, testValueOfX(code, 2U, 0)); } };