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:
parent
7a7d51a548
commit
077fcad4ee
|
@ -27,6 +27,7 @@
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
@ -425,9 +426,9 @@ void CheckType::checkFloatToIntegerOverflow(const Token *tok, const ValueType *v
|
||||||
continue;
|
continue;
|
||||||
if (!mSettings->isEnabled(&f, false))
|
if (!mSettings->isEnabled(&f, false))
|
||||||
continue;
|
continue;
|
||||||
if (f.floatValue > ~0ULL)
|
if (f.floatValue >= std::exp2(mSettings->long_long_bit))
|
||||||
floatToIntegerOverflowError(tok, f);
|
floatToIntegerOverflowError(tok, f);
|
||||||
else if ((-f.floatValue) > (1ULL<<62))
|
else if ((-f.floatValue) > std::exp2(mSettings->long_long_bit - 1))
|
||||||
floatToIntegerOverflowError(tok, f);
|
floatToIntegerOverflowError(tok, f);
|
||||||
else if (mSettings->platformType != Settings::Unspecified) {
|
else if (mSettings->platformType != Settings::Unspecified) {
|
||||||
int bits = 0;
|
int bits = 0;
|
||||||
|
|
Loading…
Reference in New Issue