floatConversionOverflow: Avoid warnings when 255.5 is converted to unsigned char etc.

This commit is contained in:
Daniel Marjamäki 2016-12-10 23:14:40 +01:00
parent b098d5fbd6
commit 87abe1174f
2 changed files with 11 additions and 1 deletions

View File

@ -354,7 +354,7 @@ void CheckType::checkFloatToIntegerOverflow()
bits = _settings->long_long_bit;
else
continue;
if (bits < 64 && it->floatValue > (1ULL << (bits - 1)))
if (bits < 64 && it->floatValue >= (1ULL << bits))
floatToIntegerOverflowError(tok, *it);
}
}

View File

@ -238,6 +238,16 @@ private:
" return (short)1E6;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () 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()));
check("void f(void) {\n"
" return (unsigned char)255.5;\n"
"}\n");
ASSERT_EQUALS("", removeFloat(errout.str()));
}
};