diff options
author | Fred Sundvik <fsundvik@gmail.com> | 2016-02-14 21:49:31 +0200 |
---|---|---|
committer | Fred Sundvik <fsundvik@gmail.com> | 2016-02-14 21:49:31 +0200 |
commit | 8d50880686dfc2b06958fc3bd6212945ee9029c4 (patch) | |
tree | 77a593061ebf8b8b24b2ec687e22011c2e06f5ab /serial_link/protocol | |
parent | f22d2543b1d1e8dd124f244d74d6f1d34fa27654 (diff) |
Use memcpy instead of cast to avoid alignment issues
Diffstat (limited to 'serial_link/protocol')
-rw-r--r-- | serial_link/protocol/frame_validator.c | 7 |
1 files changed, 4 insertions, 3 deletions
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); } |