Fixed #6383 (FP shiftNegative - value converted to unsigned in function argument)
This commit is contained in:
parent
3082612e6d
commit
0baad496f2
|
@ -2178,6 +2178,11 @@ void CheckOther::redundantCopyError(const Token *tok,const std::string& varname)
|
||||||
// Checking for shift by negative values
|
// Checking for shift by negative values
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static bool isNegative(const Token *tok, const Settings *settings)
|
||||||
|
{
|
||||||
|
return tok->valueType() && tok->valueType()->sign == ValueType::SIGNED && tok->getValueLE(-1LL, settings);
|
||||||
|
}
|
||||||
|
|
||||||
void CheckOther::checkNegativeBitwiseShift()
|
void CheckOther::checkNegativeBitwiseShift()
|
||||||
{
|
{
|
||||||
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||||
|
@ -2213,9 +2218,9 @@ void CheckOther::checkNegativeBitwiseShift()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Get negative rhs value. preferably a value which doesn't have 'condition'.
|
// Get negative rhs value. preferably a value which doesn't have 'condition'.
|
||||||
if (tok->astOperand1()->getValueLE(-1LL, _settings))
|
if (isNegative(tok->astOperand1(), _settings))
|
||||||
negativeBitwiseShiftError(tok, 1);
|
negativeBitwiseShiftError(tok, 1);
|
||||||
else if (tok->astOperand2()->getValueLE(-1LL, _settings))
|
else if (isNegative(tok->astOperand2(), _settings))
|
||||||
negativeBitwiseShiftError(tok, 2);
|
negativeBitwiseShiftError(tok, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4788,6 +4788,10 @@ private:
|
||||||
// Negative LHS
|
// Negative LHS
|
||||||
check("const int x = -1 >> 2;");
|
check("const int x = -1 >> 2;");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting a negative value is undefined behaviour\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting a negative value is undefined behaviour\n", errout.str());
|
||||||
|
|
||||||
|
// #6383 - unsigned type
|
||||||
|
check("const int x = (unsigned int)(-1) >> 2;");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void incompleteArrayFill() {
|
void incompleteArrayFill() {
|
||||||
|
|
Loading…
Reference in New Issue