зеркало из https://github.com/github/codeql.git
C#: Rewrite null-coalsecing logic
This commit is contained in:
Родитель
01ad93d199
Коммит
6b15bf62fd
|
@ -54,16 +54,7 @@ private class Conf extends DataFlow::Configuration {
|
||||||
)
|
)
|
||||||
or
|
or
|
||||||
// A disposing method
|
// A disposing method
|
||||||
exists(Call c, Parameter p |
|
exists(Call c, Parameter p | e = c.getArgumentForParameter(p) | mayBeDisposed(p))
|
||||||
e = c.getArgumentForParameter(p)
|
|
||||||
or
|
|
||||||
// e.g `Stream.Create(input ?? new TextReader())`
|
|
||||||
exists(NullCoalescingExpr nce |
|
|
||||||
nce = c.getArgumentForParameter(p) and e = nce.getRightOperand()
|
|
||||||
)
|
|
||||||
|
|
|
||||||
mayBeDisposed(p)
|
|
||||||
)
|
|
||||||
or
|
or
|
||||||
// Things that are assigned to fields, properties, or indexers may be disposed
|
// Things that are assigned to fields, properties, or indexers may be disposed
|
||||||
exists(AssignableDefinition def, Assignable a |
|
exists(AssignableDefinition def, Assignable a |
|
||||||
|
@ -90,6 +81,8 @@ private class Conf extends DataFlow::Configuration {
|
||||||
|
|
||||||
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
|
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
|
||||||
node2.asExpr() = any(LocalScopeDisposableCreation other | other.getAnArgument() = node1.asExpr())
|
node2.asExpr() = any(LocalScopeDisposableCreation other | other.getAnArgument() = node1.asExpr())
|
||||||
|
or
|
||||||
|
exists(NullCoalescingExpr nce | node1.asExpr() = nce.getRightOperand() and node2.asExpr() = nce)
|
||||||
}
|
}
|
||||||
|
|
||||||
override predicate isBarrierOut(DataFlow::Node node) {
|
override predicate isBarrierOut(DataFlow::Node node) {
|
||||||
|
|
|
@ -83,7 +83,7 @@ class Test
|
||||||
// GOOD: Disposed automatically.
|
// GOOD: Disposed automatically.
|
||||||
using var c2 = new Timer(TimerProc);
|
using var c2 = new Timer(TimerProc);
|
||||||
|
|
||||||
// GOOD: ownership taken via ?? (false positive)
|
// GOOD: ownership taken via ??
|
||||||
StringReader source = null;
|
StringReader source = null;
|
||||||
using(XmlReader.Create(source ?? new StringReader("xml"), null))
|
using(XmlReader.Create(source ?? new StringReader("xml"), null))
|
||||||
;
|
;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче