@@ -26,17 +26,18 @@ predicate callDereferences(FunctionCall fc, int i) {
26
26
}
27
27
28
28
/**
29
- * Holds if evaluation of `op` dereferences `e`.
29
+ * Holds if evaluation of `op` dereferences `e` directly.
30
+ *
31
+ * This predicate does not recurse through function calls or arithmetic operations. To find
32
+ * such cases, use `dereferencedByOperation`.
30
33
*/
31
- predicate dereferencedByOperation ( Expr op , Expr e ) {
34
+ predicate directDereferencedByOperation ( Expr op , Expr e ) {
32
35
exists ( PointerDereferenceExpr deref |
33
36
deref .getAChild ( ) = e and
34
37
deref = op and
35
38
not deref .getParent * ( ) instanceof SizeofOperator
36
39
)
37
40
or
38
- exists ( CrementOperation crement | dereferencedByOperation ( e , op ) and crement .getOperand ( ) = e )
39
- or
40
41
exists ( ArrayExpr ae |
41
42
(
42
43
not ae .getParent ( ) instanceof AddressOfExpr and
@@ -50,6 +51,24 @@ predicate dereferencedByOperation(Expr op, Expr e) {
50
51
)
51
52
)
52
53
or
54
+ // ptr->Field
55
+ e = op .( FieldAccess ) .getQualifier ( ) and isClassPointerType ( e .getType ( ) )
56
+ or
57
+ // ptr->method()
58
+ e = op .( Call ) .getQualifier ( ) and isClassPointerType ( e .getType ( ) )
59
+ }
60
+
61
+ /**
62
+ * Holds if evaluation of `op` dereferences `e`.
63
+ *
64
+ * This includes the set of operations identified via `directDereferencedByOperation`, as well
65
+ * as calls to function that are known to dereference an argument.
66
+ */
67
+ predicate dereferencedByOperation ( Expr op , Expr e ) {
68
+ directDereferencedByOperation ( op , e )
69
+ or
70
+ exists ( CrementOperation crement | dereferencedByOperation ( e , op ) and crement .getOperand ( ) = e )
71
+ or
53
72
exists ( AddressOfExpr addof , ArrayExpr ae |
54
73
dereferencedByOperation ( addof , op ) and
55
74
addof .getOperand ( ) = ae and
@@ -74,12 +93,6 @@ predicate dereferencedByOperation(Expr op, Expr e) {
74
93
e = fc .getArgument ( i ) and
75
94
op = fc
76
95
)
77
- or
78
- // ptr->Field
79
- e = op .( FieldAccess ) .getQualifier ( ) and isClassPointerType ( e .getType ( ) )
80
- or
81
- // ptr->method()
82
- e = op .( Call ) .getQualifier ( ) and isClassPointerType ( e .getType ( ) )
83
96
}
84
97
85
98
private predicate isClassPointerType ( Type t ) {
0 commit comments