Skip to content

Commit 0653939

Browse files
Add static_asserts to ser_X_to_Y() methods
1 parent be94096 commit 0653939

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/serialize.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,28 @@ inline uint64_t ser_double_to_uint64(double x)
142142
{
143143
uint64_t tmp;
144144
std::memcpy(&tmp, &x, sizeof(x));
145+
static_assert(sizeof(tmp) == sizeof(x), "double and uint64_t assumed to have the same size");
145146
return tmp;
146147
}
147148
inline uint32_t ser_float_to_uint32(float x)
148149
{
149150
uint32_t tmp;
150151
std::memcpy(&tmp, &x, sizeof(x));
152+
static_assert(sizeof(tmp) == sizeof(x), "float and uint32_t assumed to have the same size");
151153
return tmp;
152154
}
153155
inline double ser_uint64_to_double(uint64_t y)
154156
{
155157
double tmp;
156158
std::memcpy(&tmp, &y, sizeof(y));
159+
static_assert(sizeof(tmp) == sizeof(y), "double and uint64_t assumed to have the same size");
157160
return tmp;
158161
}
159162
inline float ser_uint32_to_float(uint32_t y)
160163
{
161164
float tmp;
162165
std::memcpy(&tmp, &y, sizeof(y));
166+
static_assert(sizeof(tmp) == sizeof(y), "float and uint32_t assumed to have the same size");
163167
return tmp;
164168
}
165169

0 commit comments

Comments
 (0)