Clarify floatConversionOverflow

This commit is contained in:
Daniel Marjamäki 2017-05-22 11:04:24 +02:00
parent 19fb99d6e8
commit 8ef9ab26b1
2 changed files with 9 additions and 9 deletions

View File

@ -336,7 +336,7 @@ void CheckType::checkFloatToIntegerOverflow()
for (std::list<ValueFlow::Value>::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);
}

View File

@ -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"