Skip to content

Commit ee475b1

Browse files
committed
Fixed #10488 (FP: misra-c2012-10.7)
1 parent c76e634 commit ee475b1

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

addons/misra.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,15 @@ def isCast(expr):
617617
def is_constant_integer_expression(expr):
618618
if expr is None:
619619
return False
620+
if expr.isInt:
621+
return True
622+
if not expr.isArithmeticalOp:
623+
return False
620624
if expr.astOperand1 and not is_constant_integer_expression(expr.astOperand1):
621625
return False
622626
if expr.astOperand2 and not is_constant_integer_expression(expr.astOperand2):
623627
return False
624-
return expr.astOperand1 or expr.astOperand2 or expr.isInt
628+
return True
625629

626630
def isFunctionCall(expr, std='c99'):
627631
if not expr:

addons/test/misra/misra-test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ static void misra_10_3(uint32_t u32a, uint32_t u32b) {
679679
uint8_t res;
680680
res = u32a + u32b; // 10.3
681681
res = (uint16_t)(2U + 3U); // 10.3 10.8
682-
res = (uint16_t)2U + (uint16_t)3U;
682+
res = 2U + 3U; // no warning, utlr=unsigned char
683683
res = 0.1f; // 10.3
684684
const char c = '0'; // no-warning
685685
}
@@ -725,6 +725,7 @@ static void misra_10_7(uint16_t u16a, uint16_t u16b) {
725725
res = u32a * ( ( uint32_t ) u16a + u16b ); // no-warning
726726
res = u32a * (u16a + u16b); // 10.7
727727
u32a *= u16a + u16b; // 10.7
728+
u32a = ((uint32_t)4 * (uint32_t)2 * (uint32_t)4 ); // no-warning (#10488)
728729
}
729730

730731
static void misra_10_8(u8 x, s32 a, s32 b) {

0 commit comments

Comments
 (0)