Skip to content

Commit 0b3821c

Browse files
committed
C#: Remove false positive for out params
1 parent f23438e commit 0b3821c

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

csharp/ql/src/Likely Bugs/DangerousNonShortCircuitLogic.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class DangerousExpression extends Expr {
2727
e instanceof MethodCall
2828
or
2929
e instanceof ArrayAccess
30-
)
30+
) and
31+
not exists(Expr e | this = e.getParent*() | e.(Call).getTarget().getAParameter().isOutOrRef())
3132
}
3233
}
3334

csharp/ql/test/query-tests/Likely Bugs/DangerousNonShortCircuitLogic/DangerousNonShortCircuitLogic.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ void M()
2121
b &= c.Method(); // GOOD
2222
b |= c[0]; // GOOD
2323

24-
if (c == null | c.Method(out _)) ; // GOOD (false positive)
24+
if (c == null | c.Method(out _)) ; // GOOD
25+
if (c == null | (c.Method() | c.Method(out _))) ; // GOOD
2526
}
2627

2728
class C

csharp/ql/test/query-tests/Likely Bugs/DangerousNonShortCircuitLogic/DangerousNonShortCircuitLogic.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
| DangerousNonShortCircuitLogic.cs:16:13:16:40 | ... \| ... | Potentially dangerous use of non-short circuit logic. |
33
| DangerousNonShortCircuitLogic.cs:17:13:17:28 | ... \| ... | Potentially dangerous use of non-short circuit logic. |
44
| DangerousNonShortCircuitLogic.cs:18:13:18:34 | ... \| ... | Potentially dangerous use of non-short circuit logic. |
5-
| DangerousNonShortCircuitLogic.cs:24:13:24:39 | ... \| ... | Potentially dangerous use of non-short circuit logic. |

0 commit comments

Comments
 (0)