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