Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12452 ( False positive on Misra 10.6 for ternary operator ) #6012

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
danmar marked this conversation as resolved.
Show resolved Hide resolved
u16 z = ~u8 x ;//10.6
s32 i = c1 - c2; // 10.3
struct misra_10_6_s s;
Expand Down
Loading