aboutsummaryrefslogtreecommitdiff
path: root/src/serialize.h
diff options
context:
space:
mode:
authorSamer Afach <info@afach.de>2020-02-19 18:44:46 +0100
committerSamer Afach <info@afach.de>2020-02-19 18:44:46 +0100
commit0653939ac130eddffe40c53ac418bea305d3bf82 (patch)
treeb32fb2a081c388e0a6b20478cc21bb0dcdbb9ca0 /src/serialize.h
parentbe94096dfb0c4862e2314cbae4120d7360b08ef2 (diff)
downloadbitcoin-0653939ac130eddffe40c53ac418bea305d3bf82.tar.xz
Add static_asserts to ser_X_to_Y() methods
Diffstat (limited to 'src/serialize.h')
-rw-r--r--src/serialize.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/serialize.h b/src/serialize.h
index 4a6c5e26e4..0a43913f83 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -142,24 +142,28 @@ inline uint64_t ser_double_to_uint64(double x)
{
uint64_t tmp;
std::memcpy(&tmp, &x, sizeof(x));
+ static_assert(sizeof(tmp) == sizeof(x), "double and uint64_t assumed to have the same size");
return tmp;
}
inline uint32_t ser_float_to_uint32(float x)
{
uint32_t tmp;
std::memcpy(&tmp, &x, sizeof(x));
+ static_assert(sizeof(tmp) == sizeof(x), "float and uint32_t assumed to have the same size");
return tmp;
}
inline double ser_uint64_to_double(uint64_t y)
{
double tmp;
std::memcpy(&tmp, &y, sizeof(y));
+ static_assert(sizeof(tmp) == sizeof(y), "double and uint64_t assumed to have the same size");
return tmp;
}
inline float ser_uint32_to_float(uint32_t y)
{
float tmp;
std::memcpy(&tmp, &y, sizeof(y));
+ static_assert(sizeof(tmp) == sizeof(y), "float and uint32_t assumed to have the same size");
return tmp;
}