misra.py: Add R18.7 check (#1934)

* misra.py: Add 18.7 check

* Simplify R18.7 check

* use token.link

* Remove isStruct method
This commit is contained in:
Georgy Komarov 2019-07-01 08:00:43 +03:00 committed by Daniel Marjamäki
parent 0eedcfc160
commit f8c350fc70
2 changed files with 38 additions and 0 deletions

View File

@ -1628,6 +1628,24 @@ class MisraChecker:
self.reportError(var.nameToken, 18, 5)
def misra_18_7(self, data):
for scope in data.scopes:
if scope.type != 'Struct':
continue
token = scope.bodyStart.next
while token != scope.bodyEnd and token is not None:
# Handle nested structures to not duplicate an error.
if token.str == '{':
token = token.link
if cppcheckdata.simpleMatch(token, "[ ]"):
self.reportError(token, 18, 7)
break
token = token.next
def misra_18_8(self, data):
for var in data.variables:
if not var.isArray or not var.isLocal:
@ -2287,6 +2305,7 @@ class MisraChecker:
self.misra_17_7(cfg)
self.misra_17_8(cfg)
self.misra_18_5(cfg)
self.misra_18_7(cfg)
self.misra_18_8(cfg)
self.misra_19_2(cfg)
self.misra_20_1(cfg)

View File

@ -507,6 +507,25 @@ void misra_18_5() {
int *** p; // 18.5
}
struct {
uint16_t len;
struct {
uint8_t data_1[]; // 18.7
} nested_1;
struct named {
struct {
uint8_t len_1;
uint32_t data_2[]; // 18.7
} nested_2;
uint8_t data_3[]; // 18.7
} nested_3;
} _18_7_struct;
struct {
uint16_t len;
uint8_t data_1[ 19 ];
uint8_t data_2[ ]; // 18.7
} _18_7_struct;
void misra_18_8(int x) {
int buf1[10];
int buf2[sizeof(int)];