Skip to content

Commit

Permalink
Fix #12413 ( False positive on Misra 10.3 for bools ) (#5948)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x41head authored Feb 6, 2024
1 parent a2ecf17 commit f6b538e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
3 changes: 1 addition & 2 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2291,10 +2291,9 @@ def get_category(essential_type):
rhs_category = get_category(rhs)
if lhs_category and rhs_category and lhs_category != rhs_category and rhs_category not in ('signed','unsigned'):
self.reportError(tok, 10, 3)
if bitsOfEssentialType(lhs) < bitsOfEssentialType(rhs):
if bitsOfEssentialType(lhs) < bitsOfEssentialType(rhs) and (lhs != "bool" or tok.astOperand2.str not in ('0','1')):
self.reportError(tok, 10, 3)


def misra_10_4(self, data):
op = {'+', '-', '*', '/', '%', '&', '|', '^', '+=', '-=', ':'}
for token in data.tokenlist:
Expand Down
1 change: 1 addition & 0 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ static void misra_10_3(uint32_t u32a, uint32_t u32b) {
res = 2U + 3U; // no warning, utlr=unsigned char
res = 0.1f; // 10.3
const char c = '0'; // no-warning
bool b = true; // no-warning
uint32_t u = UINT32_C(10); // no-warning
}

Expand Down

0 comments on commit f6b538e

Please sign in to comment.