Skip to content

Commit

Permalink
Rule 9.3: Allow only { 0 } form of initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
swasti16 committed Feb 6, 2024
1 parent eaac4a2 commit 3d88105
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion addons/misra_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def parseInitializer(self, root, token):
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.isInt and self.token.getKnownIntValue() == 0 and self.token.next.str == '}':
if isFirstElement and self.token.str == '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:
Expand Down
5 changes: 4 additions & 1 deletion addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,10 @@ 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 f1[5] = { 0u }; // 9.3
unsigned int f1[ 3 ][ 2 ] = { 0U }; // 9.3
unsigned int f2[ 3 ] = { 0U }; // 9.3
float f3[ 3 ][ 2 ] = { 0.0F }; // 9.3
int g[5][2] = { 0 };
int h[2][2] = { { 0 } }; // 9.3
int i[2][2] = { { 0 }, { 0 } };
Expand Down

0 comments on commit 3d88105

Please sign in to comment.