Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,24 @@ def misra_18_5(self, data):
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:
Expand Down Expand Up @@ -2287,6 +2305,7 @@ def parseDump(self, dumpfile):
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)
Expand Down
19 changes: 19 additions & 0 deletions addons/test/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down