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]
This commit is contained in:
Heiko Bauke 2020-12-20 08:09:39 +01:00 committed by GitHub
parent 7a7d51a548
commit 077fcad4ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -27,6 +27,7 @@
#include "token.h"
#include "tokenize.h"
#include <cmath>
#include <cstddef>
#include <list>
#include <ostream>
@ -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;