File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
csharp/ql/src/Likely Bugs Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ class NestedForConditions extends SC::StructuralComparisonConfiguration {
27
27
}
28
28
}
29
29
30
+ private predicate hasChild ( Stmt outer , Element child ) {
31
+ outer = child .getParent ( )
32
+ or
33
+ hasChild ( outer , child .getParent ( ) )
34
+ }
35
+
30
36
/** A nested `for` statement that shares the same iteration variable as an outer `for` statement. */
31
37
class NestedForLoopSameVariable extends ForStmt {
32
38
ForStmt outer ;
@@ -35,7 +41,7 @@ class NestedForLoopSameVariable extends ForStmt {
35
41
MutatorOperation outerUpdate ;
36
42
37
43
NestedForLoopSameVariable ( ) {
38
- outer = this . getParent + ( ) and
44
+ hasChild ( outer , this ) and
39
45
innerUpdate = this .getAnUpdate ( ) and
40
46
outerUpdate = outer .getAnUpdate ( ) and
41
47
innerUpdate .getOperand ( ) = iteration .getAnAccess ( ) and
@@ -88,7 +94,7 @@ class NestedForLoopSameVariable extends ForStmt {
88
94
89
95
/** Finds elements inside the outer loop that are no longer guarded by the loop invariant. */
90
96
private ControlFlow:: Node getAnUnguardedNode ( ) {
91
- result . getElement ( ) . getParent + ( ) = getOuterForStmt ( ) . getBody ( ) and
97
+ hasChild ( getOuterForStmt ( ) . getBody ( ) , result . getElement ( ) ) and
92
98
(
93
99
result =
94
100
this .getCondition ( ) .( ControlFlowElement ) .getAControlFlowExitNode ( ) .getAFalseSuccessor ( )
Original file line number Diff line number Diff line change 12
12
import csharp
13
13
import semmle.code.csharp.frameworks.System
14
14
15
+ private predicate equalsMethodChild ( EqualsMethod equals , Element child ) {
16
+ child = equals
17
+ or
18
+ equalsMethodChild ( equals , child .getParent ( ) )
19
+ }
20
+
15
21
predicate nodeBeforeParameterAccess ( ControlFlow:: Node node ) {
16
22
exists ( EqualsMethod equals | equals .getBody ( ) = node .getElement ( ) )
17
23
or
18
24
exists ( EqualsMethod equals , Parameter param , ControlFlow:: Node mid |
19
25
equals .getParameter ( 0 ) = param and
20
- equals . getAChild * ( ) = mid .getElement ( ) and
26
+ equalsMethodChild ( equals , mid .getElement ( ) ) and
21
27
nodeBeforeParameterAccess ( mid ) and
22
28
not param .getAnAccess ( ) = mid .getElement ( ) and
23
29
mid .getASuccessor ( ) = node
You can’t perform that action at this time.
0 commit comments