From 077fcad4ee29545b2e9d8c5823ac4570be78f920 Mon Sep 17 00:00:00 2001 From: Heiko Bauke Date: Sun, 20 Dec 2020 08:09:39 +0100 Subject: [PATCH] fix compile-time rounding error and fix overflow check (#2937) fixes implicit conversion from 'unsigned long long' to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion] --- lib/checktype.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/checktype.cpp b/lib/checktype.cpp index e46a8142d..30d6acb8c 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -27,6 +27,7 @@ #include "token.h" #include "tokenize.h" +#include #include #include #include @@ -425,9 +426,9 @@ void CheckType::checkFloatToIntegerOverflow(const Token *tok, const ValueType *v continue; if (!mSettings->isEnabled(&f, false)) continue; - if (f.floatValue > ~0ULL) + if (f.floatValue >= std::exp2(mSettings->long_long_bit)) floatToIntegerOverflowError(tok, f); - else if ((-f.floatValue) > (1ULL<<62)) + else if ((-f.floatValue) > std::exp2(mSettings->long_long_bit - 1)) floatToIntegerOverflowError(tok, f); else if (mSettings->platformType != Settings::Unspecified) { int bits = 0;