Modified rule 11.9 (#1262)

This commit is contained in:
Swasti Shrivastava 2018-05-23 19:18:07 +05:30 committed by Daniel Marjamäki
parent 8daa8520ba
commit ea5417b8af
2 changed files with 28 additions and 14 deletions

View File

@ -808,7 +808,7 @@ def misra_11_4(data):
def misra_11_5(data):
for token in data.tokenlist:
if not isCast(token):
if token.str == "=" and token.next.str != "(":
if token.astOperand1 and token.astOperand2 and token.str == "=" and token.next.str != "(":
vt1 = token.astOperand1.valueType
vt2 = token.astOperand2.valueType
if not vt1 or not vt2:
@ -901,18 +901,19 @@ def misra_11_8(data):
def misra_11_9(data):
compiled = re.compile(r'#define ([A-Za-z_][A-Za-z_0-9]*) (.*)')
for directive in data.directives:
res1 = compiled.match(directive.str)
if not res1:
continue
name = res1.group(1)
if name == 'NULL':
continue
value = res1.group(2).replace(' ', '')
if value == '((void*)0)':
reportError(directive, 11, 9)
for token in data.tokenlist:
if token.astOperand1 and token.astOperand2 and token.str in ["=", "==", "!=", "?", ":"]:
vt1 = token.astOperand1.valueType
vt2 = token.astOperand2.valueType
if not vt1 or not vt2:
continue
if vt1.pointer > 0 and vt2.pointer == 0 and token.astOperand2.str == "NULL":
continue
if (token.astOperand2.values and vt1.pointer > 0 and
vt2.pointer == 0 and token.astOperand2.values):
for val in token.astOperand2.values:
if val.intvalue == 0:
reportError(token, 11, 9)
def misra_12_1_sizeof(rawTokens):
state = 0

View File

@ -203,7 +203,20 @@ char * misra_11_8(const char *str) {
return (char *)str; // 11.8
}
#define MISRA_11_9 ((void*)0) // 11.9
#define MISRA_11_9_NULL_1 (1-1)
#define MISRA_11_9_NULL_2 ( void * ) 0
#define MISRA_11_9_NULL_3 NULL
void misra_11_9(){
int *p1 = (5-5); //11.9
int *p2 = MISRA_11_9_NULL_2 ; // no-warning
int *p3 = MISRA_11_9_NULL_3 ; // no-warning
if ( p1 == MISRA_11_9_NULL_1 ) //11.9
{
;
}
}
void misra_12_1() {
sz = sizeof x + y; // 12.1