Merge pull request #238 from commaai/misra_17_8

Misra 17.8: a function parameter should not be modified
master
George Hotz 2019-07-03 13:36:49 -07:00 committed by GitHub
commit 18c9e88bc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 15 deletions

View File

@ -49,27 +49,30 @@ int append_crc(char *in, int in_len) {
}
crc &= 0x7fffU;
}
int in_len_copy = in_len;
for (int i = 14; i >= 0; i--) {
in[in_len] = (crc >> (unsigned int)(i)) & 1U;
in_len++;
in[in_len_copy] = (crc >> (unsigned int)(i)) & 1U;
in_len_copy++;
}
return in_len;
return in_len_copy;
}
int append_bits(char *in, int in_len, char *app, int app_len) {
int in_len_copy = in_len;
for (int i = 0; i < app_len; i++) {
in[in_len] = app[i];
in_len++;
in[in_len_copy] = app[i];
in_len_copy++;
}
return in_len;
return in_len_copy;
}
int append_int(char *in, int in_len, int val, int val_len) {
int in_len_copy = in_len;
for (int i = val_len-1; i >= 0; i--) {
in[in_len] = ((unsigned int)(val) & (1U << (unsigned int)(i))) != 0;
in_len++;
in[in_len_copy] = ((unsigned int)(val) & (1U << (unsigned int)(i))) != 0;
in_len_copy++;
}
return in_len;
return in_len_copy;
}
int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) {

View File

@ -307,22 +307,23 @@ void putch(const char a) {
}
void puts(const char *a) {
for (;*a;a++) {
if (*a == '\n') putch('\r');
putch(*a);
for (const char *in = a; *in; in++) {
if (*in == '\n') putch('\r');
putch(*in);
}
}
void putui(uint32_t i) {
uint32_t i_copy = i;
char str[11];
uint8_t idx = 10;
str[idx] = '\0';
idx--;
do {
str[idx] = (i % 10) + 0x30;
str[idx] = (i_copy % 10) + 0x30;
idx--;
i /= 10;
} while (i != 0);
i_copy /= 10;
} while (i_copy != 0);
puts(str + idx + 1);
}