Fix #12298: false positive: misra-c2012-9.3 (#5812)

This commit is contained in:
Swasti Shrivastava 2023-12-30 17:35:25 +05:30 committed by GitHub
parent 4c7aae3a16
commit 681b15f5c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -311,8 +311,7 @@ class InitializerParser:
if self.ed and self.ed.isValue:
if not isDesignated and len(self.rootStack) > 0 and self.rootStack[-1][1] == self.root:
self.rootStack[-1][0].markStuctureViolation(self.token)
if isFirstElement and self.token.str == '0' and self.token.next.str == '}':
if isFirstElement and self.token.isInt and self.token.getKnownIntValue() == 0 and self.token.next.str == '}':
# Zero initializer causes recursive initialization
self.root.initializeChildren()
elif self.token.isString and self.ed.valueType and self.ed.valueType.pointer > 0:

View File

@ -441,6 +441,7 @@ static void misra_9_empty_or_zero_initializers(void) {
int e[2][2] = { { 1 , 2 }, {} }; // 9.2
int f[5] = { 0 };
int f1[5] = { 0u }; // no-warning #11298
int g[5][2] = { 0 };
int h[2][2] = { { 0 } }; // 9.3
int i[2][2] = { { 0 }, { 0 } };