diff --git a/addons/misra.py b/addons/misra.py index 8c5f99d4227..bec39767284 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -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: @@ -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) diff --git a/addons/test/misra-test.c b/addons/test/misra-test.c index 0fd22a59fd4..bf12361e028 100644 --- a/addons/test/misra-test.c +++ b/addons/test/misra-test.c @@ -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)];