Skip to content

Commit ea8ef16

Browse files
committed
add fix for findGotoLabel in misra.py
1 parent 112e7e1 commit ea8ef16

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

addons/misra.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,14 @@ def numberOfParentheses(tok1, tok2):
11691169
def findGotoLabel(gotoToken):
11701170
label = gotoToken.next.str
11711171
tok = gotoToken.next.next
1172+
functionScope = gotoToken.scope
1173+
while functionScope and functionScope.type != 'Function':
1174+
functionScope = functionScope.nestedIn
1175+
functionEnd = functionScope.bodyEnd if functionScope else None
11721176
while tok:
1173-
if tok.str == '}' and tok.scope.type == 'Function':
1177+
if tok is functionEnd:
1178+
break
1179+
if functionEnd is None and tok.str == '}' and tok.scope and tok.scope.type == 'Function':
11741180
break
11751181
if tok.str == label and tok.next.str == ':':
11761182
return tok

addons/test/misra/misra-test.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,23 @@ static void misra_15_3(int a) {
14641464
}
14651465
}
14661466

1467+
struct misra_15_2_s {
1468+
int a;
1469+
int b;
1470+
};
1471+
1472+
static void misra_15_2_initializer_list(void) {
1473+
int err = 0;
1474+
if (err == 0) {
1475+
err = 1;
1476+
goto done; // 15.1
1477+
}
1478+
struct misra_15_2_s s = { 1, 2 };
1479+
(void)s;
1480+
done:
1481+
return;
1482+
}
1483+
14671484
static void misra_15_4(void) {
14681485
misra_15_4_label:
14691486
return;

0 commit comments

Comments
 (0)