From 8ef9ab26b1d43595d5aaf8f486a02cc0fe77abf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 22 May 2017 11:04:24 +0200 Subject: [PATCH] Clarify floatConversionOverflow --- lib/checktype.cpp | 8 ++++---- test/testtype.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 5eacee222..a5e449663 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -336,7 +336,7 @@ void CheckType::checkFloatToIntegerOverflow() for (std::list::const_iterator it = op1->values().begin(); it != op1->values().end(); ++it) { if (it->valueType != ValueFlow::Value::FLOAT) continue; - if (it->inconclusive && !_settings->inconclusive) + if (!_settings->isEnabled(&(*it), false)) continue; if (it->floatValue > ~0ULL) floatToIntegerOverflowError(tok, *it); @@ -367,9 +367,9 @@ void CheckType::checkFloatToIntegerOverflow() void CheckType::floatToIntegerOverflowError(const Token *tok, const ValueFlow::Value &value) { std::ostringstream errmsg; - errmsg << "Undefined behaviour: float (" << value.floatValue << ") conversion overflow."; - reportError(tok, - Severity::error, + errmsg << "Undefined behaviour: float (" << value.floatValue << ") to integer conversion overflow."; + reportError(getErrorPath(tok, &value, "float to integer conversion"), + value.condition ? Severity::warning : Severity::error, "floatConversionOverflow", errmsg.str(), CWE190, value.inconclusive); } diff --git a/test/testtype.cpp b/test/testtype.cpp index fb9da76ab..70b50a002 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -222,7 +222,7 @@ private: // be stringified differently. static std::string removeFloat(const std::string& msg) { std::string::size_type pos1 = msg.find("float ("); - std::string::size_type pos2 = msg.find(") conversion"); + std::string::size_type pos2 = msg.find(") to integer conversion"); if (pos1 == std::string::npos || pos2 == std::string::npos || pos1 > pos2) return msg; return msg.substr(0,pos1+7) + msg.substr(pos2); @@ -232,22 +232,22 @@ private: check("void f(void) {\n" " return (int)1E100;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () conversion overflow.\n", removeFloat(errout.str())); + ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str())); check("void f(void) {\n" " return (int)-1E100;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () conversion overflow.\n", removeFloat(errout.str())); + ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str())); check("void f(void) {\n" " return (short)1E6;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () conversion overflow.\n", removeFloat(errout.str())); + ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str())); check("void f(void) {\n" " return (unsigned char)256.0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () conversion overflow.\n", removeFloat(errout.str())); + ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str())); check("void f(void) {\n" " return (unsigned char)255.5;\n"