Skip to content

Commit b8b4131

Browse files
committed
Scope: Address logic flaw creating multiple parents
We adjust the parent scope explicitly for loops, if statements and switch statements, but, due to a logic bug, we previously retained the existing results provided by Element.getParentScope().
1 parent 6b5021a commit b8b4131

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

cpp/common/src/codingstandards/cpp/Scope.qll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ module Internal {
3838
or
3939
exists(SwitchStmt switchStmt | switchStmt.getStmt() = e and result = switchStmt)
4040
or
41-
not result.(Loop).getStmt() = e and
42-
not result.(IfStmt).getThen() = e and
43-
not result.(IfStmt).getElse() = e and
44-
not result.(SwitchStmt).getStmt() = e and
41+
not exists(Loop loop | loop.getStmt() = e) and
42+
not exists(IfStmt ifStmt | ifStmt.getThen() = e or ifStmt.getElse() = e) and
43+
not exists(SwitchStmt switchStmt | switchStmt.getStmt() = e) and
4544
if exists(e.getParentScope())
4645
then result = e.getParentScope()
4746
else (

cpp/common/test/library/codingstandards/cpp/scope/ParentScope.expected

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
| test.cpp:11:25:11:25 | 1 | test.cpp:10:28:34:3 | { ... } |
3434
| test.cpp:11:28:11:30 | id1 | test.cpp:10:28:34:3 | { ... } |
3535
| test.cpp:11:28:11:32 | ... ++ | test.cpp:10:28:34:3 | { ... } |
36-
| test.cpp:11:35:33:5 | { ... } | test.cpp:10:28:34:3 | { ... } |
3736
| test.cpp:11:35:33:5 | { ... } | test.cpp:11:5:33:5 | for(...;...;...) ... |
3837
| test.cpp:12:7:32:7 | for(...;...;...) ... | test.cpp:11:35:33:5 | { ... } |
3938
| test.cpp:12:12:12:19 | declaration | test.cpp:11:35:33:5 | { ... } |
@@ -43,7 +42,6 @@
4342
| test.cpp:12:27:12:27 | 1 | test.cpp:11:35:33:5 | { ... } |
4443
| test.cpp:12:30:12:32 | id1 | test.cpp:11:35:33:5 | { ... } |
4544
| test.cpp:12:30:12:34 | ... ++ | test.cpp:11:35:33:5 | { ... } |
46-
| test.cpp:12:37:32:7 | { ... } | test.cpp:11:35:33:5 | { ... } |
4745
| test.cpp:12:37:32:7 | { ... } | test.cpp:12:7:32:7 | for(...;...;...) ... |
4846
| test.cpp:13:9:31:9 | { ... } | test.cpp:12:37:32:7 | { ... } |
4947
| test.cpp:14:11:14:18 | declaration | test.cpp:13:9:31:9 | { ... } |
@@ -52,17 +50,14 @@
5250
| test.cpp:16:15:16:17 | id1 | test.cpp:13:9:31:9 | { ... } |
5351
| test.cpp:16:15:16:22 | ... == ... | test.cpp:13:9:31:9 | { ... } |
5452
| test.cpp:16:22:16:22 | 0 | test.cpp:13:9:31:9 | { ... } |
55-
| test.cpp:16:25:18:11 | { ... } | test.cpp:13:9:31:9 | { ... } |
5653
| test.cpp:16:25:18:11 | { ... } | test.cpp:16:11:20:11 | if (...) ... |
5754
| test.cpp:17:13:17:20 | declaration | test.cpp:16:25:18:11 | { ... } |
5855
| test.cpp:17:17:17:19 | id1 | test.cpp:16:25:18:11 | { ... } |
59-
| test.cpp:18:18:20:11 | { ... } | test.cpp:13:9:31:9 | { ... } |
6056
| test.cpp:18:18:20:11 | { ... } | test.cpp:16:11:20:11 | if (...) ... |
6157
| test.cpp:19:13:19:20 | declaration | test.cpp:18:18:20:11 | { ... } |
6258
| test.cpp:19:17:19:19 | id1 | test.cpp:18:18:20:11 | { ... } |
6359
| test.cpp:21:11:25:11 | switch (...) ... | test.cpp:13:9:31:9 | { ... } |
6460
| test.cpp:21:19:21:21 | id1 | test.cpp:13:9:31:9 | { ... } |
65-
| test.cpp:21:24:25:11 | { ... } | test.cpp:13:9:31:9 | { ... } |
6661
| test.cpp:21:24:25:11 | { ... } | test.cpp:21:11:25:11 | switch (...) ... |
6762
| test.cpp:22:11:22:17 | case ...: | test.cpp:21:24:25:11 | { ... } |
6863
| test.cpp:22:16:22:16 | 0 | test.cpp:21:24:25:11 | { ... } |

0 commit comments

Comments
 (0)