From 8290d84472de1a2ba45c06bed3ab66365d7b99ab Mon Sep 17 00:00:00 2001 From: Konrad Grochowski Date: Sat, 9 Jun 2018 08:23:41 +0200 Subject: [PATCH] MISRA 10.4 - fixed ?: operator (#1281) x ? a : b - only a and b has to be checked --- addons/misra.py | 2 +- addons/test/misra-test.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index 606c8f3ed..d00a8f56d 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -781,7 +781,7 @@ def misra_10_1(data): reportError(token, 10, 1) def misra_10_4(data): - op = {'+', '-', '*', '/', '%', '&', '|', '^', '+=', '-=', '?', ':'} + op = {'+', '-', '*', '/', '%', '&', '|', '^', '+=', '-=', ':'} for token in data.tokenlist: if token.str not in op and not token.isComparisonOp: continue diff --git a/addons/test/misra-test.c b/addons/test/misra-test.c index b3df1ae63..1d143972c 100644 --- a/addons/test/misra-test.c +++ b/addons/test/misra-test.c @@ -153,13 +153,15 @@ void misra_10_1() { void misra_10_4(u32 x, s32 y) { z = x + 3; // 10.4 - enum misra_10_4_enuma { misra_10_4_A1, misra_10_4_A2, misra_10_4_A3 }; + enum misra_10_4_enuma { misra_10_4_A1, misra_10_4_A2, misra_10_4_A3 } a; enum misra_10_4_enumb { misra_10_4_B1, misra_10_4_B2, misra_10_4_B3 }; if ( misra_10_4_B1 > misra_10_4_A1 ) //10.4 { ; } - z = x + y; //10.4 + z = x + y; //10.4 + z = (a == misra_10_4_A3) ? x : y; //10.4 + z = (a == misra_10_4_A3) ? y : y; // no-warning } void misra_10_6(u8 x, u32 a, u32 b) {