Skip to content

Commit ed2032d

Browse files
authored
Additional fix for #12298: Rule 9.3: Allow only { 0 } form of initializer (#5955)
1 parent 05da696 commit ed2032d

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

addons/misra_9.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def parseInitializer(self, root, token):
311311
if self.ed and self.ed.isValue:
312312
if not isDesignated and len(self.rootStack) > 0 and self.rootStack[-1][1] == self.root:
313313
self.rootStack[-1][0].markStuctureViolation(self.token)
314-
if isFirstElement and self.token.isInt and self.token.getKnownIntValue() == 0 and self.token.next.str == '}':
314+
if isFirstElement and self.token.str == '0' and self.token.next.str == '}':
315315
# Zero initializer causes recursive initialization
316316
self.root.initializeChildren()
317317
elif self.token.isString and self.ed.valueType and self.ed.valueType.pointer > 0:

addons/test/misra/misra-test.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,10 @@ static void misra_9_empty_or_zero_initializers(void) {
441441
int e[2][2] = { { 1 , 2 }, {} }; // 9.2
442442

443443
int f[5] = { 0 };
444-
int f1[5] = { 0u }; // no-warning #11298
444+
int f1[5] = { 0u }; // 9.3
445+
unsigned int f1[ 3 ][ 2 ] = { 0U }; // 9.3 9.2
446+
unsigned int f2[ 3 ] = { 0U }; // 9.3
447+
float f3[ 3 ][ 2 ] = { 0.0F }; // 9.3 9.2
445448
int g[5][2] = { 0 };
446449
int h[2][2] = { { 0 } }; // 9.3
447450
int i[2][2] = { { 0 }, { 0 } };

0 commit comments

Comments
 (0)