From 681b15f5c92f77f9100307a5eb53252de5550f25 Mon Sep 17 00:00:00 2001 From: Swasti Shrivastava <37058682+swasti16@users.noreply.github.com> Date: Sat, 30 Dec 2023 17:35:25 +0530 Subject: [PATCH] Fix #12298: false positive: misra-c2012-9.3 (#5812) --- addons/misra_9.py | 3 +-- addons/test/misra/misra-test.c | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/misra_9.py b/addons/misra_9.py index f35becad7..ae46e1f17 100644 --- a/addons/misra_9.py +++ b/addons/misra_9.py @@ -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: diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index e8168ed5f..2afa7b8cf 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -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 } };