floatConversionOverflow: Avoid warnings when 255.5 is converted to unsigned char etc.
This commit is contained in:
parent
b098d5fbd6
commit
87abe1174f
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue