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 {
2727 }
2828}
2929
30+ private predicate hasChild ( Stmt outer , Element child ) {
31+ outer = child .getParent ( )
32+ or
33+ hasChild ( outer , child .getParent ( ) )
34+ }
35+
3036/** A nested `for` statement that shares the same iteration variable as an outer `for` statement. */
3137class NestedForLoopSameVariable extends ForStmt {
3238 ForStmt outer ;
@@ -35,7 +41,7 @@ class NestedForLoopSameVariable extends ForStmt {
3541 MutatorOperation outerUpdate ;
3642
3743 NestedForLoopSameVariable ( ) {
38- outer = this . getParent + ( ) and
44+ hasChild ( outer , this ) and
3945 innerUpdate = this .getAnUpdate ( ) and
4046 outerUpdate = outer .getAnUpdate ( ) and
4147 innerUpdate .getOperand ( ) = iteration .getAnAccess ( ) and
@@ -88,7 +94,7 @@ class NestedForLoopSameVariable extends ForStmt {
8894
8995 /** Finds elements inside the outer loop that are no longer guarded by the loop invariant. */
9096 private ControlFlow:: Node getAnUnguardedNode ( ) {
91- result . getElement ( ) . getParent + ( ) = getOuterForStmt ( ) . getBody ( ) and
97+ hasChild ( getOuterForStmt ( ) . getBody ( ) , result . getElement ( ) ) and
9298 (
9399 result =
94100 this .getCondition ( ) .( ControlFlowElement ) .getAControlFlowExitNode ( ) .getAFalseSuccessor ( )
Original file line number Diff line number Diff line change 1212import csharp
1313import semmle.code.csharp.frameworks.System
1414
15+ private predicate equalsMethodChild ( EqualsMethod equals , Element child ) {
16+ child = equals
17+ or
18+ equalsMethodChild ( equals , child .getParent ( ) )
19+ }
20+
1521predicate nodeBeforeParameterAccess ( ControlFlow:: Node node ) {
1622 exists ( EqualsMethod equals | equals .getBody ( ) = node .getElement ( ) )
1723 or
1824 exists ( EqualsMethod equals , Parameter param , ControlFlow:: Node mid |
1925 equals .getParameter ( 0 ) = param and
20- equals . getAChild * ( ) = mid .getElement ( ) and
26+ equalsMethodChild ( equals , mid .getElement ( ) ) and
2127 nodeBeforeParameterAccess ( mid ) and
2228 not param .getAnAccess ( ) = mid .getElement ( ) and
2329 mid .getASuccessor ( ) = node
You can’t perform that action at this time.
0 commit comments