From 2fe11d4fe8b0b2f3540494ef5774bd19475be417 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 2 Aug 2021 10:50:28 -0700 Subject: [PATCH] don't break strict-aliasing rules --- src/mesh/CryptoEngine.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mesh/CryptoEngine.cpp b/src/mesh/CryptoEngine.cpp index 9783f6255..bce9bb02f 100644 --- a/src/mesh/CryptoEngine.cpp +++ b/src/mesh/CryptoEngine.cpp @@ -32,6 +32,10 @@ void CryptoEngine::decrypt(uint32_t fromNode, uint64_t packetNum, size_t numByte void CryptoEngine::initNonce(uint32_t fromNode, uint64_t packetNum) { memset(nonce, 0, sizeof(nonce)); - *((uint64_t *)&nonce[0]) = packetNum; - *((uint32_t *)&nonce[8]) = fromNode; + + // use memcpy to avoid breaking strict-aliasing + memcpy(nonce, &packetNum, sizeof(uint64_t)); + memcpy(nonce + sizeof(uint64_t), &fromNode, sizeof(uint32_t)); + //*((uint64_t *)&nonce[0]) = packetNum; + //*((uint32_t *)&nonce[8]) = fromNode; } \ No newline at end of file