Skip to content

Commit f6b538e

Browse files
authored
Fix #12413 ( False positive on Misra 10.3 for bools ) (#5948)
1 parent a2ecf17 commit f6b538e

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

addons/misra.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,10 +2291,9 @@ def get_category(essential_type):
22912291
rhs_category = get_category(rhs)
22922292
if lhs_category and rhs_category and lhs_category != rhs_category and rhs_category not in ('signed','unsigned'):
22932293
self.reportError(tok, 10, 3)
2294-
if bitsOfEssentialType(lhs) < bitsOfEssentialType(rhs):
2294+
if bitsOfEssentialType(lhs) < bitsOfEssentialType(rhs) and (lhs != "bool" or tok.astOperand2.str not in ('0','1')):
22952295
self.reportError(tok, 10, 3)
22962296

2297-
22982297
def misra_10_4(self, data):
22992298
op = {'+', '-', '*', '/', '%', '&', '|', '^', '+=', '-=', ':'}
23002299
for token in data.tokenlist:

addons/test/misra/misra-test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ static void misra_10_3(uint32_t u32a, uint32_t u32b) {
712712
res = 2U + 3U; // no warning, utlr=unsigned char
713713
res = 0.1f; // 10.3
714714
const char c = '0'; // no-warning
715+
bool b = true; // no-warning
715716
uint32_t u = UINT32_C(10); // no-warning
716717
}
717718

0 commit comments

Comments
 (0)