1
1
import default
2
2
import semmle.code.cpp.models.implementations.Allocation
3
3
4
- query predicate newExprs ( NewExpr expr , string type , string sig , int size , int alignment , string form , string placement ) {
4
+ query predicate newExprs (
5
+ NewExpr expr , string type , string sig , int size , int alignment , string form , string placement
6
+ ) {
5
7
exists ( Function allocator , Type allocatedType |
6
8
expr .getAllocator ( ) = allocator and
7
9
sig = allocator .getFullSignature ( ) and
8
10
allocatedType = expr .getAllocatedType ( ) and
9
11
type = allocatedType .toString ( ) and
10
12
size = allocatedType .getSize ( ) and
11
13
alignment = allocatedType .getAlignment ( ) and
12
- if expr .hasAlignedAllocation ( ) then form = "aligned" else form = "" and
13
- if exists ( expr .getPlacementPointer ( ) ) then placement = expr .getPlacementPointer ( ) .toString ( ) else placement = ""
14
+ ( if expr .hasAlignedAllocation ( ) then form = "aligned" else form = "" ) and
15
+ if exists ( expr .getPlacementPointer ( ) )
16
+ then placement = expr .getPlacementPointer ( ) .toString ( )
17
+ else placement = ""
14
18
)
15
19
}
16
20
@@ -29,7 +33,9 @@ query predicate newArrayExprs(
29
33
alignment = elementType .getAlignment ( ) and
30
34
( if expr .hasAlignedAllocation ( ) then form = "aligned" else form = "" ) and
31
35
extents = concat ( Expr e | e = expr .getExtent ( ) | e .toString ( ) , ", " ) and
32
- if exists ( expr .getPlacementPointer ( ) ) then placement = expr .getPlacementPointer ( ) .toString ( ) else placement = ""
36
+ if exists ( expr .getPlacementPointer ( ) )
37
+ then placement = expr .getPlacementPointer ( ) .toString ( )
38
+ else placement = ""
33
39
)
34
40
}
35
41
@@ -106,55 +112,52 @@ query predicate deleteArrayExprs(
106
112
}
107
113
108
114
string describeAllocationFunction ( AllocationFunction f ) {
109
- result = "getSizeArg = " + f .getSizeArg ( ) .toString ( )
110
- or
111
- result = "getSizeMult = " + f .getSizeMult ( ) .toString ( )
112
- or
113
- result = "getReallocPtrArg = " + f .getReallocPtrArg ( ) .toString ( )
114
- or
115
- (
116
- f .requiresDealloc ( ) and
117
- result = "requiresDealloc"
118
- )
119
- or
120
- result = "getPlacementArgument = " + f .( OperatorNewAllocationFunction ) .getPlacementArgument ( ) .toString ( )
115
+ result = "getSizeArg = " + f .getSizeArg ( ) .toString ( )
116
+ or
117
+ result = "getSizeMult = " + f .getSizeMult ( ) .toString ( )
118
+ or
119
+ result = "getReallocPtrArg = " + f .getReallocPtrArg ( ) .toString ( )
120
+ or
121
+ f .requiresDealloc ( ) and
122
+ result = "requiresDealloc"
123
+ or
124
+ result =
125
+ "getPlacementArgument = " + f .( OperatorNewAllocationFunction ) .getPlacementArgument ( ) .toString ( )
121
126
}
122
127
123
128
query predicate allocationFunctions ( AllocationFunction f , string descr ) {
124
- descr = concat ( describeAllocationFunction ( f ) , ", " )
129
+ descr = concat ( describeAllocationFunction ( f ) , ", " )
125
130
}
126
131
127
132
string describeAllocationExpr ( AllocationExpr e ) {
128
- result = "getSizeExpr = " + e .getSizeExpr ( ) .toString ( )
129
- or
130
- result = "getSizeMult = " + e .getSizeMult ( ) .toString ( )
131
- or
132
- result = "getSizeBytes = " + e .getSizeBytes ( ) .toString ( )
133
- or
134
- result = "getReallocPtr = " + e .getReallocPtr ( ) .toString ( )
135
- or
136
- (
137
- e .requiresDealloc ( ) and
138
- result = "requiresDealloc"
139
- )
133
+ result = "getSizeExpr = " + e .getSizeExpr ( ) .toString ( )
134
+ or
135
+ result = "getSizeMult = " + e .getSizeMult ( ) .toString ( )
136
+ or
137
+ result = "getSizeBytes = " + e .getSizeBytes ( ) .toString ( )
138
+ or
139
+ result = "getReallocPtr = " + e .getReallocPtr ( ) .toString ( )
140
+ or
141
+ e .requiresDealloc ( ) and
142
+ result = "requiresDealloc"
140
143
}
141
144
142
145
query predicate allocationExprs ( AllocationExpr e , string descr ) {
143
- descr = concat ( describeAllocationExpr ( e ) , ", " )
146
+ descr = concat ( describeAllocationExpr ( e ) , ", " )
144
147
}
145
148
146
149
string describeDeallocationFunction ( DeallocationFunction f ) {
147
- result = "getFreedArg = " + f .getFreedArg ( ) .toString ( )
150
+ result = "getFreedArg = " + f .getFreedArg ( ) .toString ( )
148
151
}
149
152
150
153
query predicate deallocationFunctions ( DeallocationFunction f , string descr ) {
151
- descr = concat ( describeDeallocationFunction ( f ) , ", " )
154
+ descr = concat ( describeDeallocationFunction ( f ) , ", " )
152
155
}
153
156
154
157
string describeDeallocationExpr ( DeallocationExpr e ) {
155
- result = "getFreedExpr = " + e .getFreedExpr ( ) .toString ( )
158
+ result = "getFreedExpr = " + e .getFreedExpr ( ) .toString ( )
156
159
}
157
160
158
161
query predicate deallocationExprs ( DeallocationExpr e , string descr ) {
159
- descr = concat ( describeDeallocationExpr ( e ) , ", " )
162
+ descr = concat ( describeDeallocationExpr ( e ) , ", " )
160
163
}
0 commit comments