From 94483f907ffae88c2ecb64c3c52041cf6b9ce4fe Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 22 Mar 2024 12:12:53 -0700 Subject: [PATCH] avoid more undefined behavior --- firmware/console/binary/tunerstudio_io.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firmware/console/binary/tunerstudio_io.cpp b/firmware/console/binary/tunerstudio_io.cpp index 42b76e97b8..7abf6d052d 100644 --- a/firmware/console/binary/tunerstudio_io.cpp +++ b/firmware/console/binary/tunerstudio_io.cpp @@ -48,7 +48,8 @@ void TsChannelBase::crcAndWriteBuffer(uint8_t responseCode, size_t size) { uint32_t crc = crc32(&scratchBuffer[2], size + 1); // command part of CRC // Place the CRC at the end - *reinterpret_cast(&scratchBuffer[size + SCRATCH_BUFFER_PREFIX_SIZE]) = SWAP_UINT32(crc); + crc = SWAP_UINT32(crc); + memcpy(scratchBuffer + size + SCRATCH_BUFFER_PREFIX_SIZE, &crc, sizeof(crc)); // Write to the underlying stream write(reinterpret_cast(scratchBuffer), size + 7, true);