From 684c18f6579c0ac33dd1b3a494351401e3171b9c Mon Sep 17 00:00:00 2001 From: Swasti Shrivastava <37058682+swasti16@users.noreply.github.com> Date: Wed, 23 May 2018 13:44:17 +0530 Subject: [PATCH] Modified rule 11.3 and 11.7 (#1260) * Modified rule 11.3 and 11.7 * Changed if to elif --- addons/misra.py | 21 +++++++++++++++++---- addons/test/misra-test.c | 15 +++++++++------ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index 2a79f40d4..b055655d3 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -780,8 +780,14 @@ def misra_11_3(data): vt2 = token.astOperand1.valueType if not vt1 or not vt2: continue - if vt1.pointer == vt2.pointer and vt1.pointer > 0 and vt1.type != vt2.type and\ - vt1.isIntegral() and vt2.isIntegral() and vt1.type != 'char': + if vt1.type == 'void' or vt2.type == 'void': + continue + if (vt1.pointer > 0 and vt1.type == 'record' and + vt2.pointer > 0 and vt2.type == 'record' and + vt1.typeScopeId != vt2.typeScopeId): + reportError(token, 11, 3) + elif (vt1.pointer == vt2.pointer and vt1.pointer > 0 and + vt1.type != vt2.type and vt1.type != 'char'): reportError(token, 11, 3) @@ -842,8 +848,15 @@ def misra_11_7(data): vt2 = token.astOperand1.valueType if not vt1 or not vt2: continue - if vt1.pointer > 0 and vt1.type == 'record' and\ - vt2.pointer > 0 and vt2.type == 'record' and vt1.typeScopeId != vt2.typeScopeId: + if token.astOperand1.astOperand1: + continue + if (vt2.pointer > 0 and vt1.pointer == 0 and + not vt1.isIntegral() and not vt1.isEnum() and + vt2.type != 'void'): + reportError(token, 11, 7) + elif (vt1.pointer > 0 and vt2.pointer == 0 and + not vt2.isIntegral() and not vt2.isEnum() and + vt1.type != 'void'): reportError(token, 11, 7) diff --git a/addons/test/misra-test.c b/addons/test/misra-test.c index 3f56a78c1..189b44ae2 100644 --- a/addons/test/misra-test.c +++ b/addons/test/misra-test.c @@ -166,8 +166,10 @@ void misra_10_8(u8 x) { y = (u16)(x+x); // 10.8 } -void misra_11_3(u8* p) { +struct Fred {}; struct Wilma {}; +void misra_11_3(u8* p, struct Fred *fred) { x = (u64*)p; // 11.3 + struct Wilma *wilma = (struct Wilma *)fred; // 11.3 } void misra_11_4(u8*p) { @@ -181,18 +183,19 @@ void misra_11_4(u8*p) { void misra_11_5(void *p) { u16 *p16; x = (u8 *)p; // 11.5 - p16 = p; //11.5 + p16 = p; // 11.5 } void misra_11_6() { void *p; p = (void*)123; // 11.6 - x = (u64)p; // 11.6 + x = (u64)p; // 11.6 } -struct Fred {}; struct Wilma {}; -void misra_11_7(struct Fred *fred) { - struct Wilma *wilma = (struct Wilma *)fred; // 11.7 + +void misra_11_7(int *p, float f) { + x = ( float ) p; //11.7 + y = ( int * ) f; //11.7 } char * misra_11_8(const char *str) {