diff --git a/board/main_comms.h b/board/main_comms.h index 01c47ba07..116f95d0e 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -311,7 +311,8 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) { } // read - while ((resp_len < MIN(req->length, USBPACKET_MAX_SIZE)) && + uint16_t req_length = MIN(req->length, USBPACKET_MAX_SIZE); + while ((resp_len < req_length) && get_char(ur, (char*)&resp[resp_len])) { ++resp_len; } diff --git a/board/safety.h b/board/safety.h index e48a75502..50669e3bf 100644 --- a/board/safety.h +++ b/board/safety.h @@ -390,7 +390,8 @@ int set_safety_hooks(uint16_t mode, uint16_t param) { // convert a trimmed integer to signed 32 bit int int to_signed(int d, int bits) { int d_signed = d; - if (d >= (1 << MAX((bits - 1), 0))) { + int max_value = (1 << MAX((bits - 1), 0)); + if (d >= max_value) { d_signed = d - (1 << MAX(bits, 0)); } return d_signed; diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index 71bd19d30..1e1187128 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -264,7 +264,9 @@ static int chrysler_fwd_hook(int bus_num, int addr) { static safety_config chrysler_init(uint16_t param) { safety_config ret; - if (GET_FLAG(param, CHRYSLER_PARAM_RAM_DT)) { + + bool enable_ram_dt = GET_FLAG(param, CHRYSLER_PARAM_RAM_DT); + if (enable_ram_dt) { chrysler_platform = CHRYSLER_RAM_DT; chrysler_addrs = &CHRYSLER_RAM_DT_ADDRS; ret = BUILD_SAFETY_CFG(chrysler_ram_dt_rx_checks, CHRYSLER_RAM_DT_TX_MSGS); diff --git a/board/safety/safety_ford.h b/board/safety/safety_ford.h index 6ab123be6..0424b9d09 100644 --- a/board/safety/safety_ford.h +++ b/board/safety/safety_ford.h @@ -222,7 +222,8 @@ static void ford_rx_hook(const CANPacket_t *to_push) { // Disable controls if speeds from ABS and PCM ECUs are too far apart. // Signal: Veh_V_ActlEng float filtered_pcm_speed = ((GET_BYTE(to_push, 6) << 8) | GET_BYTE(to_push, 7)) * 0.01 / 3.6; - if (ABS(filtered_pcm_speed - ((float)vehicle_speed.values[0] / VEHICLE_SPEED_FACTOR)) > FORD_MAX_SPEED_DELTA) { + bool is_invalid_speed = ABS(filtered_pcm_speed - ((float)vehicle_speed.values[0] / VEHICLE_SPEED_FACTOR)) > FORD_MAX_SPEED_DELTA; + if (is_invalid_speed) { controls_allowed = false; } } diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index 7bbc8e661..968a1a446 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -383,7 +383,9 @@ static safety_config honda_nidec_init(uint16_t param) { enable_gas_interceptor = GET_FLAG(param, HONDA_PARAM_GAS_INTERCEPTOR); safety_config ret; - if (GET_FLAG(param, HONDA_PARAM_NIDEC_ALT)) { + + bool enable_nidec_alt = GET_FLAG(param, HONDA_PARAM_NIDEC_ALT); + if (enable_nidec_alt) { enable_gas_interceptor ? SET_RX_CHECKS(honda_nidec_alt_interceptor_rx_checks, ret) : \ SET_RX_CHECKS(honda_nidec_alt_rx_checks, ret); } else { diff --git a/tests/misra/suppressions.txt b/tests/misra/suppressions.txt index 57db05a5f..2c91f868a 100644 --- a/tests/misra/suppressions.txt +++ b/tests/misra/suppressions.txt @@ -25,5 +25,4 @@ misra-c2012-8.7 misra-c2012-8.4 misra-c2012-10.6 misra-c2012-10.3 -misra-c2012-17.3 misra-c2012-21.15