From 742d6513a150cbde8cbfc10c4168d9e5049d6ec4 Mon Sep 17 00:00:00 2001 From: Swasti Shrivastava <37058682+swasti16@users.noreply.github.com> Date: Fri, 25 May 2018 01:58:36 +0530 Subject: [PATCH] Modified rule 10.6 (#1263) * Modified rule 10.6 * Improved rule 10.6 --- addons/misra.py | 18 +++++++++++++++--- addons/test/misra-test.c | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index cf2c3146e..289d6ad46 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -170,7 +170,11 @@ def getEssentialType(expr): return typeToken.str typeToken = typeToken.next - elif expr.astOperand1 and expr.astOperand2 and expr.str in {'+', '-', '*', '/', '%', '&', '|', '^'}: + elif expr.astOperand1 and expr.astOperand2 and expr.str in {'+', '-', '*', '/', '%', '&', '|', '^', '>>', "<<", "?", ":"}: + if expr.astOperand1.valueType and expr.astOperand1.valueType.pointer > 0: + return None + if expr.astOperand2.valueType and expr.astOperand2.valueType.pointer > 0: + return None e1 = getEssentialType(expr.astOperand1) e2 = getEssentialType(expr.astOperand2) if not e1 or not e2: @@ -184,6 +188,9 @@ def getEssentialType(expr): return types[i1] except ValueError: return None + elif expr.str == "~": + e1 = getEssentialType(expr.astOperand1) + return e1 return None @@ -767,6 +774,9 @@ def misra_10_6(data): for token in data.tokenlist: if token.str != '=' or not token.astOperand1 or not token.astOperand2: continue + if (token.astOperand2.str not in {'+', '-', '*', '/', '%', '&', '|', '^', '>>', "<<", "?", ":", '~'} and + not isCast(token.astOperand2)): + continue vt1 = token.astOperand1.valueType vt2 = token.astOperand2.valueType if not vt1 or vt1.pointer > 0: @@ -776,7 +786,10 @@ def misra_10_6(data): try: intTypes = ['char', 'short', 'int', 'long', 'long long'] index1 = intTypes.index(vt1.type) - e = getEssentialType(token.astOperand2) + if isCast(token.astOperand2): + e = vt2.type + else: + e = getEssentialType(token.astOperand2) if not e: continue index2 = intTypes.index(e) @@ -785,7 +798,6 @@ def misra_10_6(data): except ValueError: pass - def misra_10_8(data): for token in data.tokenlist: if not isCast(token): diff --git a/addons/test/misra-test.c b/addons/test/misra-test.c index 7ca9b6467..963276430 100644 --- a/addons/test/misra-test.c +++ b/addons/test/misra-test.c @@ -162,8 +162,10 @@ void misra_10_4(u32 x, s32 y) { z = x + y; //10.4 } -void misra_10_6(u8 x) { +void misra_10_6(u8 x, u32 a, u32 b) { u16 y = x+x; // 10.6 + u16 z = ~u8 x ;//10.6 + u32 c = ( u16) ( u32 a + u32 b ); //10.6 } void misra_10_8(u8 x) {