Skip to content

fix: use false/true instead of 0/1 for bool assignments (MISRA 10.3)#2407

Open
theherrovn-sys wants to merge 1 commit into
commaai:masterfrom
theherrovn-sys:bool-0-1-misra-10.3
Open

fix: use false/true instead of 0/1 for bool assignments (MISRA 10.3)#2407
theherrovn-sys wants to merge 1 commit into
commaai:masterfrom
theherrovn-sys:bool-0-1-misra-10.3

Conversation

@theherrovn-sys
Copy link
Copy Markdown

Summary

Enforces MISRA rule 10.3 for bool assignments by catching integer literals 0/1 used where false/true are expected. Fixes #2105.

Changes

panda

  • board/drivers/can_common.h: Replace bool ret = 0 with bool ret = false and ret = 1 with ret = true in can_pop()
  • tests/misra/suppressions.txt: Add MISRA 10.3 suppression for opendbc safety/toyota.h (this will be fixed upstream via opendbc#3256)

cppcheck

The upstream cppcheck MISRA addon has been enhanced to catch bool <- 0/1 assignments in C99 and later (cppcheck-opensource/cppcheck#8340, cppcheck-opensource/cppcheck#8388). This PR fixes the violations found by the enhanced rule.

Verification

$ cppcheck --addon=misra --std=c11 board/main.c | grep misra-c2012-10.3
# (no output — all violations fixed)

- Replace bool ret = 0 with bool ret = false in can_common.h
- Replace ret = 1 with ret = true in can_common.h
- Add MISRA 10.3 suppression for opendbc toyota.h (pending opendbc PR #3256)

This enables catching int-as-bool in MISRA rule 10.3, fixing commaai#2105.
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