1
0
Fork 0

avoid potential cast to null

This commit is contained in:
Kevin Matz 2021-08-15 12:11:50 -04:00
parent 95853bd25b
commit 83e7a8d711
1 changed files with 5 additions and 0 deletions

View File

@ -96,6 +96,11 @@ struct Message
template<typename T>
static void writeType(std::vector<uint8_t>& data, T val)
{
if (val == 0) {
for (int i = sizeof(T); --i >= 0; )
data.push_back(0);
return;
}
auto raw = reinterpret_cast<uint8_t*>(val);
for (int i = sizeof(T); --i >= 0; )
data.push_back(raw[i]);