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

View File

@ -203,7 +203,20 @@ char * misra_11_8(const char *str) {
return (char *)str; // 11.8 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() { void misra_12_1() {
sz = sizeof x + y; // 12.1 sz = sizeof x + y; // 12.1