Use MathLib::bigint_bits
This commit is contained in:
parent
4cb3548e2b
commit
c4c76aa1ad
|
@ -139,7 +139,7 @@ void CheckType::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, con
|
|||
void CheckType::checkIntegerOverflow()
|
||||
{
|
||||
// unknown sizeof(int) => can't run this checker
|
||||
if (_settings->platformType == Settings::Unspecified || _settings->int_bit >= 64)
|
||||
if (_settings->platformType == Settings::Unspecified || _settings->int_bit >= MathLib::bigint_bits)
|
||||
return;
|
||||
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
|
@ -161,11 +161,11 @@ void CheckType::checkIntegerOverflow()
|
|||
else
|
||||
continue;
|
||||
|
||||
if (bits >= 64)
|
||||
if (bits >= MathLib::bigint_bits)
|
||||
continue;
|
||||
|
||||
// max value according to platform settings.
|
||||
const MathLib::bigint maxvalue = (1LL << (bits - 1)) - 1;
|
||||
const MathLib::bigint maxvalue = (((MathLib::bigint)1) << (bits - 1)) - 1;
|
||||
|
||||
// is there a overflow result value
|
||||
const ValueFlow::Value *value = tok->getValueGE(maxvalue + 1, _settings);
|
||||
|
@ -175,7 +175,7 @@ void CheckType::checkIntegerOverflow()
|
|||
continue;
|
||||
|
||||
// For left shift, it's common practice to shift into the sign bit
|
||||
if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (1LL << bits))
|
||||
if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (((MathLib::bigint)1) << bits))
|
||||
continue;
|
||||
|
||||
integerOverflowError(tok, *value);
|
||||
|
@ -396,7 +396,7 @@ void CheckType::checkFloatToIntegerOverflow()
|
|||
bits = _settings->long_long_bit;
|
||||
else
|
||||
continue;
|
||||
if (bits < 64 && it->floatValue >= (1ULL << bits))
|
||||
if (bits < MathLib::bigint_bits && it->floatValue >= (((MathLib::biguint)1) << bits))
|
||||
floatToIntegerOverflowError(tok, *it);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -266,9 +266,10 @@ static ValueFlow::Value castValue(ValueFlow::Value value, const ValueType::Sign
|
|||
value.intvalue = value.floatValue;
|
||||
}
|
||||
if (bit < MathLib::bigint_bits) {
|
||||
value.intvalue &= (1ULL << bit) - 1ULL;
|
||||
if (sign == ValueType::Sign::SIGNED && value.intvalue & (1ULL << (bit - 1ULL))) {
|
||||
value.intvalue |= ~((1ULL << bit) - 1ULL);
|
||||
const MathLib::biguint one = 1;
|
||||
value.intvalue &= (one << bit) - 1;
|
||||
if (sign == ValueType::Sign::SIGNED && value.intvalue & (one << (bit - 1))) {
|
||||
value.intvalue |= ~((one << bit) - 1ULL);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
|
@ -905,10 +906,10 @@ static void valueFlowBitAnd(TokenList *tokenlist)
|
|||
continue;
|
||||
|
||||
int bit = 0;
|
||||
while (bit <= 60 && ((1LL<<bit) < number))
|
||||
while (bit <= (MathLib::bigint_bits - 2) && ((((MathLib::bigint)1) << bit) < number))
|
||||
++bit;
|
||||
|
||||
if ((1LL<<bit) == number) {
|
||||
if (((MathLib::bigint)1) << bit) == number) {
|
||||
setTokenValue(tok, ValueFlow::Value(0), tokenlist->getSettings());
|
||||
setTokenValue(tok, ValueFlow::Value(number), tokenlist->getSettings());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue