File tree Expand file tree Collapse file tree
cpp/ql/src/semmle/code/cpp/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -236,34 +236,6 @@ private class SizelessAllocationFunction extends AllocationFunction {
236236 }
237237}
238238
239- /**
240- * Implements `OperatorNewAllocationFunction`.
241- */
242- private class OperatorNewAllocationFunctionImpl extends OperatorNewAllocationFunction {
243- OperatorNewAllocationFunctionImpl ( ) {
244- exists ( string name |
245- hasGlobalName ( name ) and
246- (
247- // operator new(bytes, ...)
248- name = "operator new"
249- or
250- // operator new[](bytes, ...)
251- name = "operator new[]"
252- )
253- )
254- }
255-
256- override int getSizeArg ( ) { result = 0 }
257-
258- override predicate requiresDealloc ( ) { not exists ( getPlacementArgument ( ) ) }
259-
260- override int getPlacementArgument ( ) {
261- getNumberOfParameters ( ) = 2 and
262- getParameter ( 1 ) .getType ( ) instanceof VoidPointerType and
263- result = 1
264- }
265- }
266-
267239/**
268240 * Holds if `sizeExpr` is an expression consisting of a subexpression
269241 * `lengthExpr` multiplied by a constant `sizeof` that is the result of a
Original file line number Diff line number Diff line change @@ -89,26 +89,6 @@ private class StandardDeallocationFunction extends DeallocationFunction {
8989 override int getFreedArg ( ) { result = freedArg }
9090}
9191
92- /**
93- * Implements `OperatorDeleteDeallocationFunction`.
94- */
95- private class OperatorDeleteDeallocationFunctionImpl extends OperatorDeleteDeallocationFunction {
96- OperatorDeleteDeallocationFunctionImpl ( ) {
97- exists ( string name |
98- hasGlobalName ( name ) and
99- (
100- // operator delete(pointer, ...)
101- name = "operator delete"
102- or
103- // operator delete[](pointer, ...)
104- name = "operator delete[]"
105- )
106- )
107- }
108-
109- override int getFreedArg ( ) { result = 0 }
110- }
111-
11292/**
11393 * An deallocation expression that is a function call, such as call to `free`.
11494 */
Original file line number Diff line number Diff line change @@ -91,10 +91,31 @@ abstract class AllocationExpr extends Expr {
9191 * `new` or `new[]` expressions. Note that `new` and `new[]` are not function
9292 * calls, but these functions may also be called directly.
9393 */
94- abstract class OperatorNewAllocationFunction extends AllocationFunction {
94+ class OperatorNewAllocationFunction extends AllocationFunction {
95+ OperatorNewAllocationFunction ( ) {
96+ exists ( string name |
97+ hasGlobalName ( name ) and
98+ (
99+ // operator new(bytes, ...)
100+ name = "operator new"
101+ or
102+ // operator new[](bytes, ...)
103+ name = "operator new[]"
104+ )
105+ )
106+ }
107+
108+ override int getSizeArg ( ) { result = 0 }
109+
110+ override predicate requiresDealloc ( ) { not exists ( getPlacementArgument ( ) ) }
111+
95112 /**
96113 * Gets the position of the placement pointer if this is a placement
97114 * `operator new` function.
98115 */
99- int getPlacementArgument ( ) { none ( ) }
116+ int getPlacementArgument ( ) {
117+ getNumberOfParameters ( ) = 2 and
118+ getParameter ( 1 ) .getType ( ) instanceof VoidPointerType and
119+ result = 1
120+ }
100121}
Original file line number Diff line number Diff line change @@ -36,5 +36,19 @@ abstract class DeallocationExpr extends Expr {
3636 * with `delete` or `delete[]` expressions. Note that `delete` and `delete[]`
3737 * are not function calls, but these functions may also be called directly.
3838 */
39- abstract class OperatorDeleteDeallocationFunction extends DeallocationFunction {
39+ class OperatorDeleteDeallocationFunction extends DeallocationFunction {
40+ OperatorDeleteDeallocationFunction ( ) {
41+ exists ( string name |
42+ hasGlobalName ( name ) and
43+ (
44+ // operator delete(pointer, ...)
45+ name = "operator delete"
46+ or
47+ // operator delete[](pointer, ...)
48+ name = "operator delete[]"
49+ )
50+ )
51+ }
52+
53+ override int getFreedArg ( ) { result = 0 }
4054}
You can’t perform that action at this time.
0 commit comments