From c4c76aa1add11cf8b28ac371c805e5447edac9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 21 Oct 2017 22:08:34 +0200 Subject: [PATCH] Use MathLib::bigint_bits --- lib/checktype.cpp | 10 +++++----- lib/valueflow.cpp | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 902192a02..f78183011 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -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); } } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index d61a2bfc6..599aa3063 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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<getSettings()); setTokenValue(tok, ValueFlow::Value(number), tokenlist->getSettings()); }