From cf6985ad15703b69b2ca4fa32b32c16b454a1303 Mon Sep 17 00:00:00 2001 From: Riccardo Date: Tue, 2 Jul 2019 17:43:44 -0700 Subject: [PATCH] memxxx function changes to be Misra compliant --- board/libc.h | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/board/libc.h b/board/libc.h index 564d29cd893ca4..83adb9c09663e8 100644 --- a/board/libc.h +++ b/board/libc.h @@ -6,32 +6,36 @@ void delay(int a) { } void *memset(void *str, int c, unsigned int n) { - unsigned int i; - for (i = 0; i < n; i++) { - *((uint8_t*)str) = c; - ++str; + uint8_t *s = str; + for (unsigned int i = 0; i < n; i++) { + *s = c; + s++; } return str; } void *memcpy(void *dest, const void *src, unsigned int n) { - unsigned int i; - // TODO: make not slow - for (i = 0; i < n; i++) { - ((uint8_t*)dest)[i] = *(uint8_t*)src; - ++src; + uint8_t *d = dest; + const uint8_t *s = src; + for (unsigned int i = 0; i < n; i++) { + *d = *s; + d++; + s++; } return dest; } int memcmp(const void * ptr1, const void * ptr2, unsigned int num) { - unsigned int i; int ret = 0; - for (i = 0; i < num; i++) { - if ( ((uint8_t*)ptr1)[i] != ((uint8_t*)ptr2)[i] ) { + const uint8_t *p1 = ptr1; + const uint8_t *p2 = ptr2; + for (unsigned int i = 0; i < num; i++) { + if (*p1 != *p2) { ret = -1; break; } + p1++; + p2++; } return ret; }