diff --git a/board/drivers/gmlan_alt.h b/board/drivers/gmlan_alt.h index c8d7f0da275303..c3d5d304e63c48 100644 --- a/board/drivers/gmlan_alt.h +++ b/board/drivers/gmlan_alt.h @@ -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) { diff --git a/board/drivers/uart.h b/board/drivers/uart.h index 65e7fdd3cf16bf..56453715aa701c 100644 --- a/board/drivers/uart.h +++ b/board/drivers/uart.h @@ -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); }