Skip to content

Commit 272d12f

Browse files
committed
Rust: Step correctly over method arguments
Previously the math was wrong and the first argument (with `i` being `0`) had two edges out of it.
1 parent b2032fc commit 272d12f

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,7 @@ class MatchExprTree extends PostOrderTree instanceof MatchExpr {
524524

525525
class MethodCallExprTree extends StandardPostOrderTree, MethodCallExpr {
526526
override AstNode getChildNode(int i) {
527-
i = 0 and
528-
result = this.getReceiver()
529-
or
530-
result = this.getArgList().getArg(i + 1)
527+
if i = 0 then result = this.getReceiver() else result = this.getArgList().getArg(i - 1)
531528
}
532529
}
533530

rust/ql/test/library-tests/controlflow/Cfg.expected

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ edges
1919
| test.rs:10:13:10:19 | map | test.rs:11:9:11:28 | ExprStmt | match |
2020
| test.rs:10:23:10:34 | PathExpr | test.rs:10:23:10:36 | CallExpr | |
2121
| test.rs:10:23:10:36 | CallExpr | test.rs:10:13:10:19 | map | |
22-
| test.rs:11:9:11:11 | map | test.rs:11:9:11:27 | MethodCallExpr | |
22+
| test.rs:11:9:11:11 | map | test.rs:11:20:11:21 | 37 | |
2323
| test.rs:11:9:11:27 | MethodCallExpr | test.rs:9:22:12:5 | BlockExpr | |
24-
| test.rs:11:9:11:28 | ExprStmt | test.rs:11:20:11:21 | 37 | |
25-
| test.rs:11:20:11:21 | 37 | test.rs:11:9:11:11 | map | |
24+
| test.rs:11:9:11:28 | ExprStmt | test.rs:11:9:11:11 | map | |
2625
| test.rs:11:20:11:21 | 37 | test.rs:11:24:11:26 | "a" | |
2726
| test.rs:11:24:11:26 | "a" | test.rs:11:9:11:27 | MethodCallExpr | |
2827
| test.rs:17:5:33:5 | enter test_break_and_continue | test.rs:17:32:17:32 | n | |

rust/ql/test/library-tests/variables/Cfg.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,10 @@ edges
707707
| variables.rs:332:5:332:17 | ExprStmt | variables.rs:332:5:332:13 | PathExpr | |
708708
| variables.rs:332:15:332:15 | a | variables.rs:332:5:332:16 | CallExpr | |
709709
| variables.rs:333:5:333:27 | MethodCallExpr | variables.rs:334:5:334:17 | ExprStmt | |
710-
| variables.rs:333:5:333:28 | ExprStmt | variables.rs:333:25:333:26 | 10 | |
711-
| variables.rs:333:6:333:11 | RefExpr | variables.rs:333:5:333:27 | MethodCallExpr | |
710+
| variables.rs:333:5:333:28 | ExprStmt | variables.rs:333:11:333:11 | a | |
711+
| variables.rs:333:6:333:11 | RefExpr | variables.rs:333:25:333:26 | 10 | |
712712
| variables.rs:333:11:333:11 | a | variables.rs:333:6:333:11 | RefExpr | |
713-
| variables.rs:333:25:333:26 | 10 | variables.rs:333:11:333:11 | a | |
713+
| variables.rs:333:25:333:26 | 10 | variables.rs:333:5:333:27 | MethodCallExpr | |
714714
| variables.rs:334:5:334:13 | PathExpr | variables.rs:334:15:334:15 | a | |
715715
| variables.rs:334:5:334:16 | CallExpr | variables.rs:329:17:335:1 | BlockExpr | |
716716
| variables.rs:334:5:334:17 | ExprStmt | variables.rs:334:5:334:13 | PathExpr | |

0 commit comments

Comments
 (0)