Clarify floatConversionOverflow
This commit is contained in:
parent
19fb99d6e8
commit
8ef9ab26b1
|
@ -336,7 +336,7 @@ void CheckType::checkFloatToIntegerOverflow()
|
||||||
for (std::list<ValueFlow::Value>::const_iterator it = op1->values().begin(); it != op1->values().end(); ++it) {
|
for (std::list<ValueFlow::Value>::const_iterator it = op1->values().begin(); it != op1->values().end(); ++it) {
|
||||||
if (it->valueType != ValueFlow::Value::FLOAT)
|
if (it->valueType != ValueFlow::Value::FLOAT)
|
||||||
continue;
|
continue;
|
||||||
if (it->inconclusive && !_settings->inconclusive)
|
if (!_settings->isEnabled(&(*it), false))
|
||||||
continue;
|
continue;
|
||||||
if (it->floatValue > ~0ULL)
|
if (it->floatValue > ~0ULL)
|
||||||
floatToIntegerOverflowError(tok, *it);
|
floatToIntegerOverflowError(tok, *it);
|
||||||
|
@ -367,9 +367,9 @@ void CheckType::checkFloatToIntegerOverflow()
|
||||||
void CheckType::floatToIntegerOverflowError(const Token *tok, const ValueFlow::Value &value)
|
void CheckType::floatToIntegerOverflowError(const Token *tok, const ValueFlow::Value &value)
|
||||||
{
|
{
|
||||||
std::ostringstream errmsg;
|
std::ostringstream errmsg;
|
||||||
errmsg << "Undefined behaviour: float (" << value.floatValue << ") conversion overflow.";
|
errmsg << "Undefined behaviour: float (" << value.floatValue << ") to integer conversion overflow.";
|
||||||
reportError(tok,
|
reportError(getErrorPath(tok, &value, "float to integer conversion"),
|
||||||
Severity::error,
|
value.condition ? Severity::warning : Severity::error,
|
||||||
"floatConversionOverflow",
|
"floatConversionOverflow",
|
||||||
errmsg.str(), CWE190, value.inconclusive);
|
errmsg.str(), CWE190, value.inconclusive);
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ private:
|
||||||
// be stringified differently.
|
// be stringified differently.
|
||||||
static std::string removeFloat(const std::string& msg) {
|
static std::string removeFloat(const std::string& msg) {
|
||||||
std::string::size_type pos1 = msg.find("float (");
|
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)
|
if (pos1 == std::string::npos || pos2 == std::string::npos || pos1 > pos2)
|
||||||
return msg;
|
return msg;
|
||||||
return msg.substr(0,pos1+7) + msg.substr(pos2);
|
return msg.substr(0,pos1+7) + msg.substr(pos2);
|
||||||
|
@ -232,22 +232,22 @@ private:
|
||||||
check("void f(void) {\n"
|
check("void f(void) {\n"
|
||||||
" return (int)1E100;\n"
|
" return (int)1E100;\n"
|
||||||
"}\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"
|
check("void f(void) {\n"
|
||||||
" return (int)-1E100;\n"
|
" return (int)-1E100;\n"
|
||||||
"}\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"
|
check("void f(void) {\n"
|
||||||
" return (short)1E6;\n"
|
" return (short)1E6;\n"
|
||||||
"}\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"
|
check("void f(void) {\n"
|
||||||
" return (unsigned char)256.0;\n"
|
" return (unsigned char)256.0;\n"
|
||||||
"}\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"
|
check("void f(void) {\n"
|
||||||
" return (unsigned char)255.5;\n"
|
" return (unsigned char)255.5;\n"
|
||||||
|
|
Loading…
Reference in New Issue