interest: avoid misaligned memory access in getNonce()
refs #4175
Change-Id: Ib42a48d0da4ff4e2c0bd5fe33b01eee927be3138
diff --git a/src/interest.cpp b/src/interest.cpp
index b35814c..05951be 100644
--- a/src/interest.cpp
+++ b/src/interest.cpp
@@ -333,8 +333,11 @@
if (!m_nonce.hasWire())
const_cast<Interest*>(this)->setNonce(random::generateWord32());
- if (m_nonce.value_size() == sizeof(uint32_t))
- return *reinterpret_cast<const uint32_t*>(m_nonce.value());
+ if (m_nonce.value_size() == sizeof(uint32_t)) {
+ uint32_t nonce = 0;
+ std::memcpy(&nonce, m_nonce.value(), sizeof(uint32_t));
+ return nonce;
+ }
else {
// for compatibility reasons. Should be removed eventually
return readNonNegativeInteger(m_nonce);