Skip to content

Fix #14628: MISRA: avoid false positives for true/false after #14607#8388

Open
varshneydevansh wants to merge 2 commits intodanmar:mainfrom
varshneydevansh:post_misra
Open

Fix #14628: MISRA: avoid false positives for true/false after #14607#8388
varshneydevansh wants to merge 2 commits intodanmar:mainfrom
varshneydevansh:post_misra

Conversation

@varshneydevansh
Copy link
Copy Markdown
Contributor

This #14628 is a follow-up to #14607.

After #14607, MISRA rule 10.3 report false positives for assignments written with true/false in C99 and later.

The issue is that in C, <stdbool.h> often expands:

  • true -> 1
  • false -> 0

So checking only the processed RHS token text is not enough to distinguish:

  • source true/false
  • source 0/1

This change uses the RHS token macro origin (macroName) to preserve that distinction.

Behavior after this change:

  • source true/false: allowed
  • source 0/1:
    • allowed in c89
    • reported as MISRA 10.3 in c99/c11/c17/c18/c23

Changes:

  • update addons/misra.py rule 10.3 to distinguish boolean macro spelling from integer literals
  • extend C11 MISRA tests to cover true/false initialization and assignment cases

Downstream reproduction:

  • verified against commaai/panda using CPPCHECK_DIR=/Users/devanshvarshney/cppcheck
  • false positives on bool <- true/false disappeared
  • remaining 10.3 reports are actual source 0/1 assignments

Related Context:

@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant