Skip to content

Conversation

@AgentsLogic
Copy link

@AgentsLogic AgentsLogic commented Jan 3, 2026

This PR implements the fix for issue #2105 by:

  1. Fixing all integer-to-bool violations in board/main.c:

    • safety_tx_blocked = 0safety_tx_blocked = false
    • safety_rx_invalid = 0safety_rx_invalid = false
    • led_set(LED_RED, 1)led_set(LED_RED, true)
    • led_set(LED_RED, 0)led_set(LED_RED, false)
  2. Adding cppcheck patch for enforcing MISRA compliant Boolean values:

  3. Testing:

    • All MISRA linter tests pass
    • The new check successfully detects violations
    • All violations have been fixed

Changes

  • board/main.c: Replace integer literals with boolean literals
  • tests/misra/install.sh: Apply cppcheck patch after checkout
  • tests/misra/0001-feat-enforcing-MISRA-compliant-Boolean-values.patch: Patch file for cppcheck

Fixes #2105

- Replace integer assignments to bools with true/false
  - safety_tx_blocked = 0 -> false
  - safety_rx_invalid = 0 -> false
  - led_set(LED_RED, 1) -> led_set(LED_RED, true)
  - led_set(LED_RED, 0) -> led_set(LED_RED, false)

- Add cppcheck patch for enforcing MISRA compliant Boolean values
  - Patch implements CheckBool::checkAssignedLiteralToBoolean check
  - Detects and reports integer-to-bool assignments
  - Ref: danmar/cppcheck#7110

- Update install.sh to apply the patch during cppcheck build
  - Patch is applied after checking out cppcheck 2.16.0
  - Gracefully handles case where patch is already applied

Fixes issue commaai#2105
@AgentsLogic AgentsLogic marked this pull request as draft January 3, 2026 18:26
@AgentsLogic AgentsLogic marked this pull request as ready for review January 3, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cppcheck: catch ints as bools

1 participant