tooBigBitwiseShift: check all calculations, not only in function bodies
This commit is contained in:
parent
696c5b8100
commit
0cf551351b
|
@ -57,40 +57,35 @@ void CheckType::checkTooBigBitwiseShift()
|
||||||
if (_settings->platformType == Settings::Unspecified)
|
if (_settings->platformType == Settings::Unspecified)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
// C++ and macro: OUT(x<<y)
|
||||||
for (std::size_t i = 0; i < functions; ++i) {
|
if (_tokenizer->isCPP() && Token::Match(tok, "[;{}] %name% (") && Token::simpleMatch(tok->linkAt(2), ") ;") && tok->next()->isUpperCaseName() && !tok->next()->function())
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
tok = tok->linkAt(2);
|
||||||
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
|
|
||||||
// C++ and macro: OUT(x<<y)
|
|
||||||
if (_tokenizer->isCPP() && Token::Match(tok, "[;{}] %name% (") && Token::simpleMatch(tok->linkAt(2), ") ;") && tok->next()->isUpperCaseName() && !tok->next()->function())
|
|
||||||
tok = tok->linkAt(2);
|
|
||||||
|
|
||||||
if (!tok->astOperand1() || !tok->astOperand2())
|
if (!tok->astOperand1() || !tok->astOperand2())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!Token::Match(tok, "<<|>>|<<=|>>="))
|
if (!Token::Match(tok, "<<|>>|<<=|>>="))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// get number of bits of lhs
|
// get number of bits of lhs
|
||||||
const ValueType *lhstype = tok->astOperand1()->valueType();
|
const ValueType *lhstype = tok->astOperand1()->valueType();
|
||||||
if (!lhstype || !lhstype->isIntegral() || lhstype->pointer >= 1U)
|
if (!lhstype || !lhstype->isIntegral() || lhstype->pointer >= 1U)
|
||||||
continue;
|
continue;
|
||||||
int lhsbits = 0;
|
int lhsbits = 0;
|
||||||
if (lhstype->type <= ValueType::Type::INT)
|
if (lhstype->type <= ValueType::Type::INT)
|
||||||
lhsbits = _settings->int_bit;
|
lhsbits = _settings->int_bit;
|
||||||
else if (lhstype->type == ValueType::Type::LONG)
|
else if (lhstype->type == ValueType::Type::LONG)
|
||||||
lhsbits = _settings->long_bit;
|
lhsbits = _settings->long_bit;
|
||||||
else if (lhstype->type == ValueType::Type::LONGLONG)
|
else if (lhstype->type == ValueType::Type::LONGLONG)
|
||||||
lhsbits = _settings->long_long_bit;
|
lhsbits = _settings->long_long_bit;
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Get biggest rhs value. preferably a value which doesn't have 'condition'.
|
// Get biggest rhs value. preferably a value which doesn't have 'condition'.
|
||||||
const ValueFlow::Value *value = tok->astOperand2()->getValueGE(lhsbits, _settings);
|
const ValueFlow::Value *value = tok->astOperand2()->getValueGE(lhsbits, _settings);
|
||||||
if (value && _settings->isEnabled(value, false))
|
if (value && _settings->isEnabled(value, false))
|
||||||
tooBigBitwiseShiftError(tok, lhsbits, *value);
|
tooBigBitwiseShiftError(tok, lhsbits, *value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue