From 2226819deac35ead640a79db3912c802ce270d1d Mon Sep 17 00:00:00 2001 From: Aryan Date: Wed, 21 Feb 2024 16:50:06 +0530 Subject: [PATCH 1/5] change code for ternary operator --- addons/misra.py | 4 ++-- src/test.c | 5 +++++ src/toimport.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 src/test.c create mode 100644 src/toimport.h diff --git a/addons/misra.py b/addons/misra.py index 62a87666490..7482e949d92 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -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? diff --git a/src/test.c b/src/test.c new file mode 100644 index 00000000000..05a6df2c020 --- /dev/null +++ b/src/test.c @@ -0,0 +1,5 @@ +static int f(int c){ + int b=0; // no issue + b = (c==0) ? 0 : 1; //misra-c2012-10.6 + return b+c; +} \ No newline at end of file diff --git a/src/toimport.h b/src/toimport.h new file mode 100644 index 00000000000..55c8902227b --- /dev/null +++ b/src/toimport.h @@ -0,0 +1 @@ +void *dostuff(void*p, const void*a); From c19aff592301a89aa2209a2fdcd36807742372d8 Mon Sep 17 00:00:00 2001 From: Aryan Date: Wed, 21 Feb 2024 16:51:03 +0530 Subject: [PATCH 2/5] delete local files --- src/test.c | 5 ----- src/toimport.h | 1 - 2 files changed, 6 deletions(-) delete mode 100644 src/test.c delete mode 100644 src/toimport.h diff --git a/src/test.c b/src/test.c deleted file mode 100644 index 05a6df2c020..00000000000 --- a/src/test.c +++ /dev/null @@ -1,5 +0,0 @@ -static int f(int c){ - int b=0; // no issue - b = (c==0) ? 0 : 1; //misra-c2012-10.6 - return b+c; -} \ No newline at end of file diff --git a/src/toimport.h b/src/toimport.h deleted file mode 100644 index 55c8902227b..00000000000 --- a/src/toimport.h +++ /dev/null @@ -1 +0,0 @@ -void *dostuff(void*p, const void*a); From c06801dc17938b87622149893a71811b97b4365b Mon Sep 17 00:00:00 2001 From: Aryan Date: Wed, 21 Feb 2024 17:24:45 +0530 Subject: [PATCH 3/5] add test --- addons/test/misra/misra-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index fc0abdab7ca..d035be8e33f 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -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 + u16 b = (y2 == 0) ? 0 : 1; // no-warning u16 z = ~u8 x ;//10.6 s32 i = c1 - c2; // 10.3 struct misra_10_6_s s; From 5dccf964601f7ce53e8dc9864b6995a1de163f79 Mon Sep 17 00:00:00 2001 From: Aryan Date: Wed, 21 Feb 2024 18:18:28 +0530 Subject: [PATCH 4/5] test edit --- addons/test/misra/misra-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index d035be8e33f..ca164fa62cc 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -769,7 +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 - u16 b = (y2 == 0) ? 0 : 1; // no-warning + int b = (y2 == 0) ? 0 : 1; // no-warning u16 z = ~u8 x ;//10.6 s32 i = c1 - c2; // 10.3 struct misra_10_6_s s; From f678a179d3a8f759ecfab3c53ef096bc44eaac4c Mon Sep 17 00:00:00 2001 From: Aryan Date: Wed, 21 Feb 2024 18:38:50 +0530 Subject: [PATCH 5/5] change test condition --- addons/test/misra/misra-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index ca164fa62cc..d36ad6c25d4 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -769,7 +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 == 0) ? 0 : 1; // no-warning + 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;