Skip to content

Commit 681b15f

Browse files
authored
Fix #12298: false positive: misra-c2012-9.3 (#5812)
1 parent 4c7aae3 commit 681b15f

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

addons/misra_9.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +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-
315-
if isFirstElement and self.token.str == '0' and self.token.next.str == '}':
314+
if isFirstElement and self.token.isInt and self.token.getKnownIntValue() == 0 and self.token.next.str == '}':
316315
# Zero initializer causes recursive initialization
317316
self.root.initializeChildren()
318317
elif self.token.isString and self.ed.valueType and self.ed.valueType.pointer > 0:

addons/test/misra/misra-test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ 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
444445
int g[5][2] = { 0 };
445446
int h[2][2] = { { 0 } }; // 9.3
446447
int i[2][2] = { { 0 }, { 0 } };

0 commit comments

Comments
 (0)