diff options
author | Pieter Wuille <pieter@wuille.net> | 2021-05-18 12:36:53 -0700 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2021-05-24 16:15:05 -0700 |
commit | fff1cae43af959a601cf2558cb3c77f3c2b1aa80 (patch) | |
tree | f84c771447fb072e76515d65179f4cd0dd5c31b1 /src/test/fuzz | |
parent | afd964d70b6f7583ecf89c380f80db07f5b66a60 (diff) | |
download | bitcoin-fff1cae43af959a601cf2558cb3c77f3c2b1aa80.tar.xz |
Convert uses of double-serialization to {En,De}codeDouble
Diffstat (limited to 'src/test/fuzz')
-rw-r--r-- | src/test/fuzz/float.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/test/fuzz/float.cpp b/src/test/fuzz/float.cpp index f806c82d14..e95d593b22 100644 --- a/src/test/fuzz/float.cpp +++ b/src/test/fuzz/float.cpp @@ -7,10 +7,13 @@ #include <streams.h> #include <test/fuzz/FuzzedDataProvider.h> #include <test/fuzz/fuzz.h> +#include <util/serfloat.h> #include <version.h> #include <cassert> #include <cstdint> +#include <cmath> +#include <limits> FUZZ_TARGET(float) { @@ -19,12 +22,17 @@ FUZZ_TARGET(float) { const double d = fuzzed_data_provider.ConsumeFloatingPoint<double>(); (void)memusage::DynamicUsage(d); - assert(ser_uint64_to_double(ser_double_to_uint64(d)) == d); - CDataStream stream(SER_NETWORK, INIT_PROTO_VERSION); - stream << d; - double d_deserialized; - stream >> d_deserialized; - assert(d == d_deserialized); + uint64_t encoded = EncodeDouble(d); + if constexpr (std::numeric_limits<double>::is_iec559) { + if (!std::isnan(d)) { + uint64_t encoded_in_memory; + std::copy((const unsigned char*)&d, (const unsigned char*)(&d + 1), (unsigned char*)&encoded_in_memory); + assert(encoded_in_memory == encoded); + } + } + double d_deserialized = DecodeDouble(encoded); + assert(std::isnan(d) == std::isnan(d_deserialized)); + assert(std::isnan(d) || d == d_deserialized); } } |