Merge pull request #6085 from tamasvajk/feature/unsafe

C#: Fix `Modifiable::isUnsafe` to handle declarations extracted from assemblies
This commit is contained in:
Tamás Vajk
2021-06-16 10:30:09 +02:00
committed by GitHub
3 changed files with 9 additions and 2 deletions

View File

@@ -0,0 +1,2 @@
lgtm,codescanning
* The `Modifiable::isUnsafe` predicate has been fixed to handle symbols that are not extracted from source code.

View File

@@ -86,7 +86,12 @@ class Modifiable extends Declaration, @modifiable {
predicate isConst() { this.hasModifier("const") }
/** Holds if this declaration is `unsafe`. */
predicate isUnsafe() { this.hasModifier("unsafe") }
predicate isUnsafe() {
this.hasModifier("unsafe") or
this.(Parameterizable).getAParameter().getType() instanceof PointerType or
this.(Property).getType() instanceof PointerType or
this.(Callable).getReturnType() instanceof PointerType
}
/** Holds if this declaration is `async`. */
predicate isAsync() { this.hasModifier("async") }

View File

@@ -1,3 +1,3 @@
import csharp
select any(Modifiable m | m.isUnsafe())
select any(Modifiable m | m.isUnsafe() and m.fromSource())