Skip to content

Commit c0dfbc2

Browse files
committed
C#: Only do it for out parameters.
1 parent df03269 commit c0dfbc2

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ module Expressions {
511511
QualifiedWriteAccessOutRef() {
512512
exists(AssignableDefinitions::OutRefDefinition def |
513513
def.getExpr() = this and
514-
def.getTargetAccess() instanceof QualifiableExpr
514+
def.getTargetAccess() instanceof QualifiableExpr and
515+
def.getTargetAccess().isOutArgument()
515516
)
516517
}
517518

@@ -522,25 +523,26 @@ module Expressions {
522523
first = this
523524
}
524525

525-
private QualifiableExpr getOutRefAccess(int i) {
526+
private QualifiableExpr getOutAccess(int i) {
526527
result =
527528
rank[i + 1](AssignableDefinitions::OutRefDefinition def |
528529
def.getExpr() = this and
529-
def.getTargetAccess() instanceof QualifiableExpr
530+
def.getTargetAccess() instanceof QualifiableExpr and
531+
def.getTargetAccess().isOutArgument()
530532
|
531533
def order by def.getIndex()
532534
).getTargetAccess()
533535
}
534536

535-
private QualifiableExpr getLastOutRefAccess() {
537+
private QualifiableExpr getLastOutAccess() {
536538
exists(int last |
537-
result = this.getOutRefAccess(last) and
538-
not exists(this.getOutRefAccess(last + 1))
539+
result = this.getOutAccess(last) and
540+
not exists(this.getOutAccess(last + 1))
539541
)
540542
}
541543

542544
final override predicate last(AstNode last, Completion c) {
543-
last = this.getLastOutRefAccess() and
545+
last = this.getLastOutAccess() and
544546
c.isValidFor(last)
545547
}
546548

@@ -559,13 +561,13 @@ module Expressions {
559561
or
560562
// Flow from this element to the first write access.
561563
pred = this and
562-
succ = this.getOutRefAccess(0) and
564+
succ = this.getOutAccess(0) and
563565
c.isValidFor(pred) and
564566
c instanceof NormalCompletion
565567
or
566568
// Flow from one access to the next
567-
exists(int i | pred = this.getOutRefAccess(i) |
568-
succ = this.getOutRefAccess(i + 1) and
569+
exists(int i | pred = this.getOutAccess(i) |
570+
succ = this.getOutAccess(i + 1) and
569571
c.isValidFor(pred) and
570572
c instanceof NormalCompletion
571573
)

0 commit comments

Comments
 (0)