From f6b538e855f0bacea33c4074664628024ef39dc6 Mon Sep 17 00:00:00 2001 From: Aryan <53595853+0x41head@users.noreply.github.com> Date: Tue, 6 Feb 2024 22:13:50 +0530 Subject: [PATCH] Fix #12413 ( False positive on Misra 10.3 for bools ) (#5948) --- addons/misra.py | 3 +-- addons/test/misra/misra-test.c | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index a48629b986f..14a17703596 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -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: diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 2afa7b8cfec..da9243cf0b7 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -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 }