From ea8ef1674162a69950e59c8c034db28acd2462bc Mon Sep 17 00:00:00 2001 From: Nick James Kirkby <20824939+driftregion@users.noreply.github.com> Date: Sun, 20 Sep 2026 00:25:44 -0700 Subject: [PATCH] add fix for findGotoLabel in misra.py --- addons/misra.py | 8 +++++++- addons/test/misra/misra-test.c | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/addons/misra.py b/addons/misra.py index 7abc99f365a..7c7774c52e3 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1169,8 +1169,14 @@ def numberOfParentheses(tok1, tok2): def findGotoLabel(gotoToken): label = gotoToken.next.str tok = gotoToken.next.next + functionScope = gotoToken.scope + while functionScope and functionScope.type != 'Function': + functionScope = functionScope.nestedIn + functionEnd = functionScope.bodyEnd if functionScope else None while tok: - if tok.str == '}' and tok.scope.type == 'Function': + if tok is functionEnd: + break + if functionEnd is None and tok.str == '}' and tok.scope and tok.scope.type == 'Function': break if tok.str == label and tok.next.str == ':': return tok diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 6b6f52342aa..2871fd871d4 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -1464,6 +1464,23 @@ static void misra_15_3(int a) { } } +struct misra_15_2_s { + int a; + int b; +}; + +static void misra_15_2_initializer_list(void) { + int err = 0; + if (err == 0) { + err = 1; + goto done; // 15.1 + } + struct misra_15_2_s s = { 1, 2 }; + (void)s; +done: + return; +} + static void misra_15_4(void) { misra_15_4_label: return;