Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional fix for #12298: Rule 9.3: Allow only { 0 } form of initializer #5955

Merged
merged 1 commit into from
Feb 7, 2024
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
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 9.2
unsigned int f2[ 3 ] = { 0U }; // 9.3
float f3[ 3 ][ 2 ] = { 0.0F }; // 9.3 9.2
int g[5][2] = { 0 };
int h[2][2] = { { 0 } }; // 9.3
int i[2][2] = { { 0 }, { 0 } };
Expand Down
Loading