Skip to content

Commit 4f41b44

Browse files
committed
C#: Some more precise flow.
1 parent c6ae475 commit 4f41b44

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

csharp/ql/lib/semmle/code/csharp/Assignable.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ module AssignableInternal {
286286
/** Holds if the local variable definition is at the top level of the pattern. */
287287
predicate isTopLevel() { this = pm.getPattern().(BindingPatternExpr).getVariableDeclExpr() }
288288

289+
/** Holds of this local variable definition is a part of a tuple pattern. */
290+
predicate isInTuple() { this.getParent() instanceof TuplePatternExpr }
291+
289292
/** Gets the pattern match that this local variable declaration (pattern) belongs to. */
290293
PatternMatch getMatch() { result = pm }
291294
}
@@ -720,12 +723,15 @@ module AssignableDefinitions {
720723
/** Gets the underlying local variable declaration. */
721724
LocalVariableDeclExpr getDeclaration() { result = lvpd }
722725

723-
override Expr getSource() { this.isTopLevel() and result = this.getMatch().getExpr() }
726+
override Expr getSource() { result = this.getMatch().getExpr() }
724727

725728
override string toString() { result = this.getDeclaration().toString() }
726729

727730
/** Holds if the local variable definition is at the top level of the pattern. */
728731
predicate isTopLevel() { lvpd.isTopLevel() }
732+
733+
/** Holds of this local variable definition is a part of a tuple pattern. */
734+
predicate isInTuple() { lvpd.isInTuple() }
729735
}
730736

731737
/**

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ module LocalFlow {
640640
def.getSource() = e and
641641
(
642642
scope = def.getExpr() and
643-
isSuccessor = true
643+
isSuccessor = true and
644+
not def instanceof AssignableDefinitions::PatternDefinition
644645
or
645646
exists(AssignableDefinitions::PatternDefinition def0 | def = def0 and def0.isTopLevel() |
646647
scope = def0.getMatch().(IsExpr) and
@@ -663,7 +664,7 @@ module LocalFlow {
663664
isSuccessor = false and
664665
def =
665666
any(AssignableDefinitions::PatternDefinition apd |
666-
e = apd.getDeclaration() and not apd.isTopLevel()
667+
e = apd.getDeclaration() and not apd.isTopLevel() and not apd.isInTuple()
667668
)
668669
}
669670
}

0 commit comments

Comments
 (0)