Skip to content

Commit 8dff8e7

Browse files
authored
Merge pull request #2637 from hvitved/csharp/non-assigned-fields-bad-magic
Approved by calumgrant
2 parents 4efc418 + f4c255c commit 8dff8e7

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

csharp/ql/src/Dead Code/NonAssignedFields.ql

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ ValueOrRefType getAReferencedType(Type t) {
3434

3535
predicate isTypeExternallyInitialized(ValueOrRefType t) {
3636
// The type got created via a call to PtrToStructure().
37-
exists(MethodCall mc |
37+
exists(MethodCall mc, Type t0, Expr arg |
3838
mc.getTarget() = any(SystemRuntimeInteropServicesMarshalClass c).getPtrToStructureTypeMethod() and
39-
t = getAReferencedType(mc.getArgument(1).(TypeofExpr).getTypeAccess().getTarget())
40-
)
41-
or
42-
// The type got created via a call to PtrToStructure().
43-
exists(MethodCall mc |
44-
mc.getTarget() = any(SystemRuntimeInteropServicesMarshalClass c).getPtrToStructureObjectMethod() and
45-
t = getAReferencedType(mc.getArgument(1).getType())
39+
t = getAReferencedType(t0) and
40+
arg = mc.getArgument(1)
41+
|
42+
t0 = arg.(TypeofExpr).getTypeAccess().getTarget()
43+
or
44+
t0 = arg.getType()
4645
)
4746
or
4847
// An extern method exists which could initialize the type.

0 commit comments

Comments
 (0)