Commit b70e34d
authored
Fix #14607: MISRA: make rule 10.3 warn on bool <- 0/1 in C99 and later (#8340)
Fix #14607.
This updates MISRA rule 10.3 in `addons/misra.py` so that assignments of
integer literals `0` and `1` to `bool` are only exempted in C89.
Behavior after this change:
- C89: keep the existing behavior and allow `bool <- 0/1`
- C99/C11/C17/C18/C23: report MISRA 10.3 for `bool <- 0/1`
The motivation is that in C99 and later, `bool`/`true`/`false` are
available, so the current unconditional exemption for `0` and `1` causes
a MISRA 10.3 false negative.
Changes:
- update `addons/misra.py` rule 10.3 to make the `bool <- 0/1` exemption
standard-dependent
- add C89-side coverage in `addons/test/misra/misra-test.c`
- add C11-side coverage in `addons/test/misra/misra-test-c11.c`
- add a release notes entry
Related Context:
- Earlier discussion: #7110
- Downstream issue: commaai/panda#21051 parent 18492b0 commit b70e34d
4 files changed
Lines changed: 24 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2472 | 2472 | | |
2473 | 2473 | | |
2474 | 2474 | | |
2475 | | - | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
2476 | 2483 | | |
2477 | 2484 | | |
2478 | 2485 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
726 | 726 | | |
727 | 727 | | |
728 | 728 | | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
729 | 733 | | |
730 | 734 | | |
731 | 735 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
0 commit comments