From 54459e694eaa6dcc3f5eab0c4c9a15c6a88aa93d Mon Sep 17 00:00:00 2001 From: Aryan <53595853+0x41head@users.noreply.github.com> Date: Sun, 11 Feb 2024 04:20:36 +0530 Subject: [PATCH] update cppcheck (#1859) * update cppcheck * Update tests/misra/install.sh * delete cppcheck cache * remove misra 5.8 erroors * fixed uninitialized data error * suppress misra-c2012-2.3 and misra-c2012-2.4 * reinstate cache to fix mutation test * rerun for mutation test * increase timeout for mutation test * styling * comments + variable name changes * Update tests/misra/install.sh Co-authored-by: Adeeb Shihadeh * Update install.sh * more variable name changes * condition on defining CANPacket_t * just cherry pick * fix build --------- Co-authored-by: Adeeb Shihadeh --- .github/workflows/test.yaml | 2 +- board/can_definitions.h | 2 ++ board/drivers/can_common.h | 4 ++-- board/drivers/usb.h | 34 +++++++++++++++++----------------- board/health.h | 6 +++--- board/main_comms.h | 6 +++--- tests/misra/install.sh | 5 ++++- 7 files changed, 32 insertions(+), 27 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 718aaa8a..5f65560d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -120,7 +120,7 @@ jobs: timeout-minutes: 1 run: ${{ env.RUN }} "cd tests/misra && ./test_misra.sh" - name: MISRA mutation tests - timeout-minutes: 3 + timeout-minutes: 4 run: ${{ env.RUN }} "cd tests/misra && ./test_mutation.py" python_linter: diff --git a/board/can_definitions.h b/board/can_definitions.h index daae4d04..db3d6217 100644 --- a/board/can_definitions.h +++ b/board/can_definitions.h @@ -15,6 +15,7 @@ const uint8_t PANDA_BUS_CNT = 4U; #define CANPACKET_DATA_SIZE_MAX 8U #endif +#ifndef STM32F2 typedef struct { unsigned char reserved : 1; unsigned char bus : 3; @@ -26,6 +27,7 @@ typedef struct { unsigned char checksum; unsigned char data[CANPACKET_DATA_SIZE_MAX]; } __attribute__((packed, aligned(4))) CANPacket_t; +#endif const unsigned char dlc_to_len[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U}; diff --git a/board/drivers/can_common.h b/board/drivers/can_common.h index 574c7cfd..db77617e 100644 --- a/board/drivers/can_common.h +++ b/board/drivers/can_common.h @@ -277,10 +277,10 @@ void can_send(CANPacket_t *to_push, uint8_t bus_number, bool skip_tx_hook) { } } -bool is_speed_valid(uint32_t speed, const uint32_t *speeds, uint8_t len) { +bool is_speed_valid(uint32_t speed, const uint32_t *all_speeds, uint8_t len) { bool ret = false; for (uint8_t i = 0U; i < len; i++) { - if (speeds[i] == speed) { + if (all_speeds[i] == speed) { ret = true; } } diff --git a/board/drivers/usb.h b/board/drivers/usb.h index 99ba126c..ed74b932 100644 --- a/board/drivers/usb.h +++ b/board/drivers/usb.h @@ -79,7 +79,7 @@ void refresh_can_tx_slots_available(void); #define STS_SETUP_COMP 4 #define STS_SETUP_UPDT 6 -uint8_t resp[USBPACKET_MAX_SIZE]; +uint8_t response[USBPACKET_MAX_SIZE]; // for the repeating interfaces #define DSCR_INTERFACE_LEN 9 @@ -557,19 +557,19 @@ void usb_setup(void) { break; case STRING_OFFSET_ISERIAL: #ifdef UID_BASE - resp[0] = 0x02 + (12 * 4); - resp[1] = 0x03; + response[0] = 0x02 + (12 * 4); + response[1] = 0x03; // 96 bits = 12 bytes for (int i = 0; i < 12; i++){ uint8_t cc = ((uint8_t *)UID_BASE)[i]; - resp[2 + (i * 4)] = to_hex_char((cc >> 4) & 0xFU); - resp[2 + (i * 4) + 1] = '\0'; - resp[2 + (i * 4) + 2] = to_hex_char((cc >> 0) & 0xFU); - resp[2 + (i * 4) + 3] = '\0'; + response[2 + (i * 4)] = to_hex_char((cc >> 4) & 0xFU); + response[2 + (i * 4) + 1] = '\0'; + response[2 + (i * 4) + 2] = to_hex_char((cc >> 0) & 0xFU); + response[2 + (i * 4) + 3] = '\0'; } - USB_WritePacket(resp, MIN(resp[0], setup.b.wLength.w), 0); + USB_WritePacket(response, MIN(response[0], setup.b.wLength.w), 0); #else USB_WritePacket((const uint8_t *)string_serial_desc, MIN(sizeof(string_serial_desc), setup.b.wLength.w), 0); #endif @@ -599,10 +599,10 @@ void usb_setup(void) { } break; case USB_REQ_GET_STATUS: - // empty resp? - resp[0] = 0; - resp[1] = 0; - USB_WritePacket((void*)&resp, 2, 0); + // empty response? + response[0] = 0; + response[1] = 0; + USB_WritePacket((void*)&response, 2, 0); USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK; break; case USB_REQ_SET_INTERFACE: @@ -648,10 +648,10 @@ void usb_setup(void) { control_req.param2 = setup.b.wIndex.w; control_req.length = setup.b.wLength.w; - resp_len = comms_control_handler(&control_req, resp); + resp_len = comms_control_handler(&control_req, response); // response pending if -1 was returned if (resp_len != -1) { - USB_WritePacket(resp, MIN(resp_len, setup.b.wLength.w), 0); + USB_WritePacket(response, MIN(resp_len, setup.b.wLength.w), 0); USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK; } } @@ -877,7 +877,7 @@ void usb_irqhandler(void) { print(" IN PACKET QUEUE\n"); #endif // TODO: always assuming max len, can we get the length? - USB_WritePacket((void *)resp, comms_can_read(resp, 0x40), 1); + USB_WritePacket((void *)response, comms_can_read(response, 0x40), 1); } break; @@ -888,9 +888,9 @@ void usb_irqhandler(void) { print(" IN PACKET QUEUE\n"); #endif // TODO: always assuming max len, can we get the length? - int len = comms_can_read(resp, 0x40); + int len = comms_can_read(response, 0x40); if (len > 0) { - USB_WritePacket((void *)resp, len, 1); + USB_WritePacket((void *)response, len, 1); } } break; diff --git a/board/health.h b/board/health.h index 8745cb0e..fc7661ca 100644 --- a/board/health.h +++ b/board/health.h @@ -21,10 +21,10 @@ struct __attribute__((packed)) health_t { uint8_t power_save_enabled_pkt; uint8_t heartbeat_lost_pkt; uint16_t alternative_experience_pkt; - float interrupt_load; + float interrupt_load_pkt; uint8_t fan_power; - uint8_t safety_rx_checks_invalid; - uint16_t spi_checksum_error_count; + uint8_t safety_rx_checks_invalid_pkt; + uint16_t spi_checksum_error_count_pkt; uint8_t fan_stall_count; uint16_t sbu1_voltage_mV; uint16_t sbu2_voltage_mV; diff --git a/board/main_comms.h b/board/main_comms.h index 116f95d0..f535af66 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -28,14 +28,14 @@ int get_health_pkt(void *dat) { health->alternative_experience_pkt = alternative_experience; health->power_save_enabled_pkt = power_save_status == POWER_SAVE_STATUS_ENABLED; health->heartbeat_lost_pkt = heartbeat_lost; - health->safety_rx_checks_invalid = safety_rx_checks_invalid; + health->safety_rx_checks_invalid_pkt = safety_rx_checks_invalid; - health->spi_checksum_error_count = spi_checksum_error_count; + health->spi_checksum_error_count_pkt = spi_checksum_error_count; health->fault_status_pkt = fault_status; health->faults_pkt = faults; - health->interrupt_load = interrupt_load; + health->interrupt_load_pkt = interrupt_load; health->fan_power = fan_state.power; health->fan_stall_count = fan_state.total_stall_count; diff --git a/tests/misra/install.sh b/tests/misra/install.sh index 21396264..a29b1111 100755 --- a/tests/misra/install.sh +++ b/tests/misra/install.sh @@ -9,8 +9,11 @@ if [ ! -d "$CPPCHECK_DIR" ]; then fi cd $CPPCHECK_DIR + VERS="2.13.0" -git fetch --tags origin $VERS +git fetch --all --tags git checkout $VERS +git cherry-pick -n f6b538e855f0bacea33c4074664628024ef39dc6 + #make clean make MATCHCOMPILTER=yes CXXFLAGS="-O2" -j8