Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5326b3

Browse files
committed
C++: Give OperatorNewAllocationFunction, OperatorDeleteAllocationFunction proper interfaces.
1 parent 7f54379 commit b5326b3

6 files changed

Lines changed: 28 additions & 18 deletions

File tree

cpp/ql/src/Critical/NewDelete.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import cpp
66
import semmle.code.cpp.controlflow.SSA
77
import semmle.code.cpp.dataflow.DataFlow
8-
import semmle.code.cpp.models.implementations.Allocation
9-
import semmle.code.cpp.models.implementations.Deallocation
108

119
/**
1210
* Holds if `alloc` is a use of `malloc` or `new`. `kind` is

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import semmle.code.cpp.Element
66
private import semmle.code.cpp.Enclosing
77
private import semmle.code.cpp.internal.ResolveClass
88
private import semmle.code.cpp.internal.AddressConstantExpression
9-
private import semmle.code.cpp.models.implementations.Allocation
109

1110
/**
1211
* A C/C++ expression.

cpp/ql/src/semmle/code/cpp/models/implementations/Allocation.qll

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,10 @@ private class SizelessAllocationFunction extends AllocationFunction {
237237
}
238238

239239
/**
240-
* An `operator new` or `operator new[]` function that may be associated with `new` or
241-
* `new[]` expressions. Note that `new` and `new[]` are not function calls, but these
242-
* functions may also be called directly.
240+
* Implements `OperatorNewAllocationFunction`.
243241
*/
244-
class OperatorNewAllocationFunction extends AllocationFunction {
245-
OperatorNewAllocationFunction() {
242+
private class OperatorNewAllocationFunctionImpl extends OperatorNewAllocationFunction {
243+
OperatorNewAllocationFunctionImpl() {
246244
exists(string name |
247245
hasGlobalName(name) and
248246
(
@@ -259,11 +257,7 @@ class OperatorNewAllocationFunction extends AllocationFunction {
259257

260258
override predicate requiresDealloc() { not exists(getPlacementArgument()) }
261259

262-
/**
263-
* Gets the position of the placement pointer if this is a placement
264-
* `operator new` function.
265-
*/
266-
int getPlacementArgument() {
260+
override int getPlacementArgument() {
267261
getNumberOfParameters() = 2 and
268262
getParameter(1).getType() instanceof VoidPointerType and
269263
result = 1

cpp/ql/src/semmle/code/cpp/models/implementations/Deallocation.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ private class StandardDeallocationFunction extends DeallocationFunction {
9090
}
9191

9292
/**
93-
* An `operator delete` or `operator delete[]` function that may be associated
94-
* with `delete` or `delete[]` expressions. Note that `delete` and `delete[]`
95-
* are not function calls, but these functions may also be called directly.
93+
* Implements `OperatorDeleteDeallocationFunction`.
9694
*/
97-
class OperatorDeleteDeallocationFunction extends DeallocationFunction {
98-
OperatorDeleteDeallocationFunction() {
95+
private class OperatorDeleteDeallocationFunctionImpl extends OperatorDeleteDeallocationFunction {
96+
OperatorDeleteDeallocationFunctionImpl() {
9997
exists(string name |
10098
hasGlobalName(name) and
10199
(

cpp/ql/src/semmle/code/cpp/models/interfaces/Allocation.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,16 @@ abstract class AllocationExpr extends Expr {
8585
*/
8686
predicate requiresDealloc() { any() }
8787
}
88+
89+
/**
90+
* An `operator new` or `operator new[]` function that may be associated with
91+
* `new` or `new[]` expressions. Note that `new` and `new[]` are not function
92+
* calls, but these functions may also be called directly.
93+
*/
94+
abstract class OperatorNewAllocationFunction extends AllocationFunction {
95+
/**
96+
* Gets the position of the placement pointer if this is a placement
97+
* `operator new` function.
98+
*/
99+
int getPlacementArgument() { none()}
100+
}

cpp/ql/src/semmle/code/cpp/models/interfaces/Deallocation.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@ abstract class DeallocationExpr extends Expr {
3030
*/
3131
Expr getFreedExpr() { none() }
3232
}
33+
34+
/**
35+
* An `operator delete` or `operator delete[]` function that may be associated
36+
* with `delete` or `delete[]` expressions. Note that `delete` and `delete[]`
37+
* are not function calls, but these functions may also be called directly.
38+
*/
39+
abstract class OperatorDeleteDeallocationFunction extends DeallocationFunction {
40+
}

0 commit comments

Comments
 (0)