Skip to content

Commit

Permalink
Fix #12452 ( False positive on Misra 10.6 for ternary operator ) (#6012)
Browse files Browse the repository at this point in the history
the ternary operator condition, while checking for composite expression,
wasn't being executed.
  • Loading branch information
0x41head authored Feb 27, 2024
1 parent 4f0828f commit b11b420
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,11 @@ def is_composite_expr(expr, composite_operator=False):
return False

if not composite_operator:
if (expr.str in ('+', '-', '*', '/', '%', '&', '|', '^', '>>', "<<", "?", ":", '~')):
return is_composite_expr(expr.astOperand1,True) or is_composite_expr(expr.astOperand2, True)
if expr.str == '?' and simpleMatch(expr.astOperand2, ':'):
colon = expr.astOperand2
return is_composite_expr(colon.astOperand1,True) or is_composite_expr(colon.astOperand2, True)
if (expr.str in ('+', '-', '*', '/', '%', '&', '|', '^', '>>', "<<", "?", ":", '~')):
return is_composite_expr(expr.astOperand1,True) or is_composite_expr(expr.astOperand2, True)
return False

# non constant expression?
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 @@ -769,6 +769,7 @@ struct misra_10_6_s {
static void misra_10_6(u8 x, char c1, char c2) {
u16 y1 = x+x; // 10.6
u16 y2 = (0x100u - 0x80u); // rhs is not a composite expression because it's a constant expression
int b = (y2 == y2) ? 0 : 1; // no-warning
u16 z = ~u8 x ;//10.6
s32 i = c1 - c2; // 10.3
struct misra_10_6_s s;
Expand Down

0 comments on commit b11b420

Please sign in to comment.