From ee475b181d8eb9bddea7195c6fbc722ce5fc0b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 19 Sep 2021 20:21:45 +0200 Subject: [PATCH] Fixed #10488 (FP: misra-c2012-10.7) --- addons/misra.py | 6 +++++- addons/test/misra/misra-test.c | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index f17a6e668..1652acd30 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -617,11 +617,15 @@ def isCast(expr): def is_constant_integer_expression(expr): if expr is None: return False + if expr.isInt: + return True + if not expr.isArithmeticalOp: + return False if expr.astOperand1 and not is_constant_integer_expression(expr.astOperand1): return False if expr.astOperand2 and not is_constant_integer_expression(expr.astOperand2): return False - return expr.astOperand1 or expr.astOperand2 or expr.isInt + return True def isFunctionCall(expr, std='c99'): if not expr: diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 4cd79cdc3..920818531 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -679,7 +679,7 @@ static void misra_10_3(uint32_t u32a, uint32_t u32b) { uint8_t res; res = u32a + u32b; // 10.3 res = (uint16_t)(2U + 3U); // 10.3 10.8 - res = (uint16_t)2U + (uint16_t)3U; + res = 2U + 3U; // no warning, utlr=unsigned char res = 0.1f; // 10.3 const char c = '0'; // no-warning } @@ -725,6 +725,7 @@ static void misra_10_7(uint16_t u16a, uint16_t u16b) { res = u32a * ( ( uint32_t ) u16a + u16b ); // no-warning res = u32a * (u16a + u16b); // 10.7 u32a *= u16a + u16b; // 10.7 + u32a = ((uint32_t)4 * (uint32_t)2 * (uint32_t)4 ); // no-warning (#10488) } static void misra_10_8(u8 x, s32 a, s32 b) {