Modified rule 11.3 and 11.7 (#1260)

* Modified rule 11.3 and 11.7

* Changed if to elif
This commit is contained in:
Swasti Shrivastava 2018-05-23 13:44:17 +05:30 committed by Daniel Marjamäki
parent 2ffbb37cee
commit 684c18f657
2 changed files with 26 additions and 10 deletions

View File

@ -780,8 +780,14 @@ def misra_11_3(data):
vt2 = token.astOperand1.valueType vt2 = token.astOperand1.valueType
if not vt1 or not vt2: if not vt1 or not vt2:
continue continue
if vt1.pointer == vt2.pointer and vt1.pointer > 0 and vt1.type != vt2.type and\ if vt1.type == 'void' or vt2.type == 'void':
vt1.isIntegral() and vt2.isIntegral() and vt1.type != 'char': 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) reportError(token, 11, 3)
@ -842,8 +848,15 @@ def misra_11_7(data):
vt2 = token.astOperand1.valueType vt2 = token.astOperand1.valueType
if not vt1 or not vt2: if not vt1 or not vt2:
continue continue
if vt1.pointer > 0 and vt1.type == 'record' and\ if token.astOperand1.astOperand1:
vt2.pointer > 0 and vt2.type == 'record' and vt1.typeScopeId != vt2.typeScopeId: 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) reportError(token, 11, 7)

View File

@ -166,8 +166,10 @@ void misra_10_8(u8 x) {
y = (u16)(x+x); // 10.8 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 x = (u64*)p; // 11.3
struct Wilma *wilma = (struct Wilma *)fred; // 11.3
} }
void misra_11_4(u8*p) { void misra_11_4(u8*p) {
@ -181,18 +183,19 @@ void misra_11_4(u8*p) {
void misra_11_5(void *p) { void misra_11_5(void *p) {
u16 *p16; u16 *p16;
x = (u8 *)p; // 11.5 x = (u8 *)p; // 11.5
p16 = p; //11.5 p16 = p; // 11.5
} }
void misra_11_6() { void misra_11_6() {
void *p; void *p;
p = (void*)123; // 11.6 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) { void misra_11_7(int *p, float f) {
struct Wilma *wilma = (struct Wilma *)fred; // 11.7 x = ( float ) p; //11.7
y = ( int * ) f; //11.7
} }
char * misra_11_8(const char *str) { char * misra_11_8(const char *str) {