Misra: Add rule 11.6

This commit is contained in:
Daniel Marjamäki 2017-04-16 11:41:00 +02:00
parent baf1df8e08
commit 657c9db478
2 changed files with 21 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <tgmath.h> // 21.11
typedef unsigned char u8;
typedef unsigned long long u64;
void misra_5_1() {
int a123456789012345678901234567890; // no-warning
@ -23,6 +24,12 @@ void misra_7_3() {
int x = 12lu; // 7.3
}
void misra_11_6() {
void *p;
p = (void*)123; // 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

View File

@ -266,6 +266,19 @@ def misra_12_1_sizeof(rawTokens):
else:
state = 0
def misra_11_6(data):
for token in data.tokenlist:
if not isCast(token):
continue
vt1 = token.valueType
vt2 = token.astOperand1.valueType
if not vt1 or not vt2:
continue
if vt1.pointer==1 and vt1.type=='void' and vt2.pointer==0:
reportError(token, 11, 6)
elif vt1.pointer==0 and vt2.pointer==1 and vt2.type=='void':
reportError(token, 11, 6)
def misra_11_7(data):
for token in data.tokenlist:
if not isCast(token):
@ -741,6 +754,7 @@ for arg in sys.argv[1:]:
if cfgNumber == 1:
misra_7_1(data.rawTokens)
misra_7_3(data.rawTokens)
misra_11_6(cfg)
misra_11_7(cfg)
misra_11_8(cfg)
misra_11_9(cfg)