From c50c0f1630bc104717c12556f89fffe2d55e33cb Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 29 Jan 2021 19:28:13 +0100 Subject: [PATCH] cppchecker fix, removed odd loop --- common/crc32.c | 21 +++++++++++---------- common/crc32.h | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/common/crc32.c b/common/crc32.c index baf6ddd28..574d499b2 100644 --- a/common/crc32.c +++ b/common/crc32.c @@ -18,17 +18,18 @@ static void crc32_byte(uint32_t *crc, const uint8_t value) { } } -void crc32_ex(const uint8_t *data, const size_t len, uint8_t *crc) { - uint32_t desfire_crc = CRC32_PRESET; - for (size_t i = 0; i < len; i++) { - crc32_byte(&desfire_crc, data[i]); - } - uint32_t crctmp = htole32(desfire_crc); - for (size_t i = 0; i < sizeof(uint32_t); i++) { - crc[i] = ((uint8_t *) &crctmp)[i]; +void crc32_ex(const uint8_t *d, const size_t n, uint8_t *crc) { + uint32_t c = CRC32_PRESET; + for (size_t i = 0; i < n; i++) { + crc32_byte(&c, d[i]); } + crc[0] = (uint8_t) c; + crc[1] = (uint8_t)(c >> 8); + crc[2] = (uint8_t)(c >> 16); + crc[3] = (uint8_t)(c >> 24); } -void crc32_append(uint8_t *data, const size_t len) { - crc32_ex(data, len, data + len); + +void crc32_append(uint8_t *d, const size_t n) { + crc32_ex(d, n, d + n); } diff --git a/common/crc32.h b/common/crc32.h index a6bbee16a..2cbe45e6c 100644 --- a/common/crc32.h +++ b/common/crc32.h @@ -11,7 +11,7 @@ #include "common.h" -void crc32_ex(const uint8_t *data, const size_t len, uint8_t *crc); -void crc32_append(uint8_t *data, const size_t len); +void crc32_ex(const uint8_t *d, const size_t n, uint8_t *crc); +void crc32_append(uint8_t *d, const size_t n); #endif