mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Convert uses of double-serialization to {En,De}codeDouble
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user