From 272028c1af7fe7e001f4c2a89691e1b9986ac67c Mon Sep 17 00:00:00 2001 From: Swasti Shrivastava <37058682+swasti16@users.noreply.github.com> Date: Fri, 9 Feb 2024 13:14:13 +0530 Subject: [PATCH] Fix #12419: false positive: misra-c2012-9.2 (#5964) --- addons/misra_9.py | 7 +++++-- addons/test/misra/misra-test.c | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/misra_9.py b/addons/misra_9.py index 4035cf0b2bf..806d27d225f 100644 --- a/addons/misra_9.py +++ b/addons/misra_9.py @@ -372,8 +372,11 @@ def unwindAndContinue(self): while self.token: if self.token.astParent.astOperand1 == self.token and self.token.astParent.astOperand2: if self.ed: - self.ed.markAsCurrent() - self.ed = self.ed.getNextValueElement(self.root) + if self.token.astParent.astOperand2.str == "{" and self.ed.isDesignated: + self.popFromStackIfExitElement() + else: + self.ed.markAsCurrent() + self.ed = self.ed.getNextValueElement(self.root) self.token = self.token.astParent.astOperand2 break diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index dfa6946cc72..7511e09f38d 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -501,6 +501,7 @@ static void misra_9_array_initializers_with_designators(void) { char c[2][2] = { [0] = {1, 2, 3} }; char d[1][2] = { [0] = 1 }; // 9.2 char e[2][2] = { { 1, 2 }, [1][0] = {3, 4} }; // 9.2 + int e1[2][2] = { [ 0 ][ 1 ] = 0, { 5, 6 } }; // no warning #12419 char f[2] = { [0] = 1, 2 }; char g[2] = { [1] = 2, [0] = 1 }; char h[2][2] = { { 1, 2 }, [1] = { 3 } }; // 9.3