@@ -12,27 +12,38 @@ import semmle.code.cpp.Function
12
12
import semmle.code.cpp.models.Models
13
13
14
14
/**
15
- * An allocation function such as `malloc`.
15
+ * An allocation expression such as call to `malloc` or a `new` expression .
16
16
*/
17
- abstract class AllocationFunction extends Function {
17
+ abstract class AllocationExpr extends Expr {
18
18
/**
19
- * Gets the index of the argument for the allocation size, if any. The actual
20
- * allocation size is the value of this argument multiplied by the result of
19
+ * Gets an expression for the allocation size, if any. The actual allocation
20
+ * size is the value of this expression multiplied by the result of
21
21
* `getSizeMult()`, in bytes.
22
22
*/
23
- int getSizeArg ( ) { none ( ) }
23
+ Expr getSizeExpr ( ) { none ( ) }
24
24
25
25
/**
26
- * Gets the index of an argument that multiplies the allocation size given by
27
- * `getSizeArg`, if any .
26
+ * Gets a constant multiplier for the allocation size given by `getSizeExpr`,
27
+ * in bytes .
28
28
*/
29
29
int getSizeMult ( ) { none ( ) }
30
30
31
31
/**
32
- * Gets the index of the input pointer argument to be reallocated, if this
33
- * is a `realloc` function .
32
+ * Gets the size of this allocation in bytes, if it is a fixed size and that
33
+ * size can be determined .
34
34
*/
35
- int getReallocPtrArg ( ) { none ( ) }
35
+ int getSizeBytes ( ) { none ( ) }
36
+
37
+ /**
38
+ * Gets the expression for the input pointer argument to be reallocated, if
39
+ * this is a `realloc` function.
40
+ */
41
+ Expr getReallocPtr ( ) { none ( ) }
42
+
43
+ /**
44
+ * Gets the type of the elements that are allocated, if it can be determined.
45
+ */
46
+ Type getAllocatedElementType ( ) { none ( ) }
36
47
37
48
/**
38
49
* Whether or not this allocation requires a corresponding deallocation of
@@ -44,38 +55,30 @@ abstract class AllocationFunction extends Function {
44
55
}
45
56
46
57
/**
47
- * An allocation expression such as call to `malloc` or a `new` expression.
58
+ * An allocation function such as `malloc`.
59
+ *
60
+ * Note: `AllocationExpr` includes calls to allocation functions, so prefer
61
+ * to use that class unless you specifically need to reason about functions.
48
62
*/
49
- abstract class AllocationExpr extends Expr {
63
+ abstract class AllocationFunction extends Function {
50
64
/**
51
- * Gets an expression for the allocation size, if any. The actual allocation
52
- * size is the value of this expression multiplied by the result of
65
+ * Gets the index of the argument for the allocation size, if any. The actual
66
+ * allocation size is the value of this argument multiplied by the result of
53
67
* `getSizeMult()`, in bytes.
54
68
*/
55
- Expr getSizeExpr ( ) { none ( ) }
69
+ int getSizeArg ( ) { none ( ) }
56
70
57
71
/**
58
- * Gets a constant multiplier for the allocation size given by `getSizeExpr`,
59
- * in bytes .
72
+ * Gets the index of an argument that multiplies the allocation size given by
73
+ * `getSizeArg`, if any .
60
74
*/
61
75
int getSizeMult ( ) { none ( ) }
62
76
63
77
/**
64
- * Gets the size of this allocation in bytes, if it is a fixed size and that
65
- * size can be determined.
66
- */
67
- int getSizeBytes ( ) { none ( ) }
68
-
69
- /**
70
- * Gets the expression for the input pointer argument to be reallocated, if
71
- * this is a `realloc` function.
72
- */
73
- Expr getReallocPtr ( ) { none ( ) }
74
-
75
- /**
76
- * Gets the type of the elements that are allocated, if it can be determined.
78
+ * Gets the index of the input pointer argument to be reallocated, if this
79
+ * is a `realloc` function.
77
80
*/
78
- Type getAllocatedElementType ( ) { none ( ) }
81
+ int getReallocPtrArg ( ) { none ( ) }
79
82
80
83
/**
81
84
* Whether or not this allocation requires a corresponding deallocation of
0 commit comments