From e2faed355b34b63af4ac71286e2365eb6c55f729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 31 Jan 2013 17:29:31 +0100 Subject: [PATCH] Fixed #4485 (False positive: Same expression of '-' when checking if float is inf) --- lib/checkother.cpp | 3 ++- test/testother.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 67366d70b..62b44b31a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3176,7 +3176,8 @@ void CheckOther::checkDuplicateExpression() if (Token::Match(tok, ",|=|return|(|&&|%oror% %var% %comp%|- %var% )|&&|%oror%|;|,") && tok->strAt(1) == tok->strAt(3)) { // float == float and float != float are valid NaN checks - if (Token::Match(tok->tokAt(2), "==|!=") && tok->next()->varId()) { + // float - float is a valid Inf check + if (Token::Match(tok->tokAt(2), "==|!=|-") && tok->next()->varId()) { const Variable * var = symbolDatabase->getVariableFromVarId(tok->next()->varId()); if (var && var->typeStartToken() == var->typeEndToken()) { if (Token::Match(var->typeStartToken(), "float|double")) diff --git a/test/testother.cpp b/test/testother.cpp index b766bf05a..1462e6dd2 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5181,8 +5181,8 @@ private: ASSERT_EQUALS("", errout.str()); } - void duplicateExpression2() { // ticket #2730 - check("int main()\n" + void duplicateExpression2() { // check if float is NaN or Inf + check("int main()\n" // ticket #2730 "{\n" " long double ldbl;\n" " double dbl, in;\n" @@ -5199,6 +5199,9 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Passing value -1.0 to sqrtl() leads to undefined result.\n" "[test.cpp:8]: (error) Passing value -1.0 to sqrt() leads to undefined result.\n" "[test.cpp:9]: (error) Passing value -1.0 to sqrtf() leads to undefined result.\n", errout.str()); + + check("float f(float x) { return x-x; }"); // ticket #4485 (Inf) + ASSERT_EQUALS("", errout.str()); } void duplicateExpression3() {