Skip to content

Commit

Permalink
safety: use CLAMP for update_counter (#1706)
Browse files Browse the repository at this point in the history
Update safety.h
  • Loading branch information
sshane authored Nov 7, 2023
1 parent e7f8b59 commit 2560349
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void update_counter(AddrCheckStruct addr_list[], int index, uint8_t counter) {
if (index != -1) {
uint8_t expected_counter = (addr_list[index].last_counter + 1U) % (addr_list[index].msg[addr_list[index].index].max_counter + 1U);
addr_list[index].wrong_counters += (expected_counter == counter) ? -1 : 1;
addr_list[index].wrong_counters = MAX(MIN(addr_list[index].wrong_counters, MAX_WRONG_COUNTERS), 0);
addr_list[index].wrong_counters = CLAMP(addr_list[index].wrong_counters, 0, MAX_WRONG_COUNTERS);
addr_list[index].last_counter = counter;
}
}
Expand Down

0 comments on commit 2560349

Please sign in to comment.