Commit c6384b90 authored by Jakob Otto's avatar Jakob Otto

Fix undefined behavior due to bad memory alignment

parent 5106b9f9
......@@ -49,9 +49,11 @@ header header::from_bytes(span<const byte> bytes) {
header result;
auto ptr = bytes.data();
result.type = *reinterpret_cast<const message_type*>(ptr);
auto payload_len = *reinterpret_cast<const uint32_t*>(ptr + 1);
uint32_t payload_len = 0;
memcpy(&payload_len, ptr + 1, 4);
result.payload_len = detail::from_network_order(payload_len);
auto operation_data = *reinterpret_cast<const uint64_t*>(ptr + 5);
uint64_t operation_data;
memcpy(&operation_data, ptr + 5, 8);
result.operation_data = detail::from_network_order(operation_data);
return result;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment