Skip to content

Commit cf6985a

Browse files
committed
memxxx function changes to be Misra compliant
1 parent 3a6cd29 commit cf6985a

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

board/libc.h

+16-12
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,36 @@ void delay(int a) {
66
}
77

88
void *memset(void *str, int c, unsigned int n) {
9-
unsigned int i;
10-
for (i = 0; i < n; i++) {
11-
*((uint8_t*)str) = c;
12-
++str;
9+
uint8_t *s = str;
10+
for (unsigned int i = 0; i < n; i++) {
11+
*s = c;
12+
s++;
1313
}
1414
return str;
1515
}
1616

1717
void *memcpy(void *dest, const void *src, unsigned int n) {
18-
unsigned int i;
19-
// TODO: make not slow
20-
for (i = 0; i < n; i++) {
21-
((uint8_t*)dest)[i] = *(uint8_t*)src;
22-
++src;
18+
uint8_t *d = dest;
19+
const uint8_t *s = src;
20+
for (unsigned int i = 0; i < n; i++) {
21+
*d = *s;
22+
d++;
23+
s++;
2324
}
2425
return dest;
2526
}
2627

2728
int memcmp(const void * ptr1, const void * ptr2, unsigned int num) {
28-
unsigned int i;
2929
int ret = 0;
30-
for (i = 0; i < num; i++) {
31-
if ( ((uint8_t*)ptr1)[i] != ((uint8_t*)ptr2)[i] ) {
30+
const uint8_t *p1 = ptr1;
31+
const uint8_t *p2 = ptr2;
32+
for (unsigned int i = 0; i < num; i++) {
33+
if (*p1 != *p2) {
3234
ret = -1;
3335
break;
3436
}
37+
p1++;
38+
p2++;
3539
}
3640
return ret;
3741
}

0 commit comments

Comments
 (0)