From 8d50880686dfc2b06958fc3bd6212945ee9029c4 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 14 Feb 2016 21:49:31 +0200 Subject: Use memcpy instead of cast to avoid alignment issues --- serial_link/protocol/frame_validator.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'serial_link') diff --git a/serial_link/protocol/frame_validator.c b/serial_link/protocol/frame_validator.c index 0a5f05068e..f326097ffa 100644 --- a/serial_link/protocol/frame_validator.c +++ b/serial_link/protocol/frame_validator.c @@ -104,7 +104,8 @@ static uint32_t crc32_byte(uint8_t *p, uint32_t bytelength) void validator_recv_frame(uint8_t* data, uint16_t size) { if (size > 4) { - uint32_t frame_crc = *(uint32_t*)(data + size - 4); + uint32_t frame_crc; + memcpy(&frame_crc, data + size -4, 4); uint32_t expected_crc = crc32_byte(data, size - 4); if (frame_crc == expected_crc) { route_incoming_frame(data, size-4); @@ -113,7 +114,7 @@ void validator_recv_frame(uint8_t* data, uint16_t size) { } void validator_send_frame(uint8_t* data, uint16_t size) { - uint32_t* crc = (uint32_t*)(data + size); - *crc = crc32_byte(data, size); + uint32_t crc = crc32_byte(data, size); + memcpy(data + size, &crc, 4); send_frame(data, size + 4); } -- cgit v1.2.3