mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
C++: Give OperatorNewAllocationFunction, OperatorDeleteAllocationFunction proper interfaces.
This commit is contained in:
@@ -5,8 +5,6 @@
|
||||
import cpp
|
||||
import semmle.code.cpp.controlflow.SSA
|
||||
import semmle.code.cpp.dataflow.DataFlow
|
||||
import semmle.code.cpp.models.implementations.Allocation
|
||||
import semmle.code.cpp.models.implementations.Deallocation
|
||||
|
||||
/**
|
||||
* Holds if `alloc` is a use of `malloc` or `new`. `kind` is
|
||||
|
||||
@@ -6,7 +6,6 @@ import semmle.code.cpp.Element
|
||||
private import semmle.code.cpp.Enclosing
|
||||
private import semmle.code.cpp.internal.ResolveClass
|
||||
private import semmle.code.cpp.internal.AddressConstantExpression
|
||||
private import semmle.code.cpp.models.implementations.Allocation
|
||||
|
||||
/**
|
||||
* A C/C++ expression.
|
||||
|
||||
@@ -237,12 +237,10 @@ private class SizelessAllocationFunction extends AllocationFunction {
|
||||
}
|
||||
|
||||
/**
|
||||
* An `operator new` or `operator new[]` function that may be associated with `new` or
|
||||
* `new[]` expressions. Note that `new` and `new[]` are not function calls, but these
|
||||
* functions may also be called directly.
|
||||
* Implements `OperatorNewAllocationFunction`.
|
||||
*/
|
||||
class OperatorNewAllocationFunction extends AllocationFunction {
|
||||
OperatorNewAllocationFunction() {
|
||||
private class OperatorNewAllocationFunctionImpl extends OperatorNewAllocationFunction {
|
||||
OperatorNewAllocationFunctionImpl() {
|
||||
exists(string name |
|
||||
hasGlobalName(name) and
|
||||
(
|
||||
@@ -259,11 +257,7 @@ class OperatorNewAllocationFunction extends AllocationFunction {
|
||||
|
||||
override predicate requiresDealloc() { not exists(getPlacementArgument()) }
|
||||
|
||||
/**
|
||||
* Gets the position of the placement pointer if this is a placement
|
||||
* `operator new` function.
|
||||
*/
|
||||
int getPlacementArgument() {
|
||||
override int getPlacementArgument() {
|
||||
getNumberOfParameters() = 2 and
|
||||
getParameter(1).getType() instanceof VoidPointerType and
|
||||
result = 1
|
||||
|
||||
@@ -90,12 +90,10 @@ private class StandardDeallocationFunction extends DeallocationFunction {
|
||||
}
|
||||
|
||||
/**
|
||||
* An `operator delete` or `operator delete[]` function that may be associated
|
||||
* with `delete` or `delete[]` expressions. Note that `delete` and `delete[]`
|
||||
* are not function calls, but these functions may also be called directly.
|
||||
* Implements `OperatorDeleteDeallocationFunction`.
|
||||
*/
|
||||
class OperatorDeleteDeallocationFunction extends DeallocationFunction {
|
||||
OperatorDeleteDeallocationFunction() {
|
||||
private class OperatorDeleteDeallocationFunctionImpl extends OperatorDeleteDeallocationFunction {
|
||||
OperatorDeleteDeallocationFunctionImpl() {
|
||||
exists(string name |
|
||||
hasGlobalName(name) and
|
||||
(
|
||||
|
||||
@@ -85,3 +85,16 @@ abstract class AllocationExpr extends Expr {
|
||||
*/
|
||||
predicate requiresDealloc() { any() }
|
||||
}
|
||||
|
||||
/**
|
||||
* An `operator new` or `operator new[]` function that may be associated with
|
||||
* `new` or `new[]` expressions. Note that `new` and `new[]` are not function
|
||||
* calls, but these functions may also be called directly.
|
||||
*/
|
||||
abstract class OperatorNewAllocationFunction extends AllocationFunction {
|
||||
/**
|
||||
* Gets the position of the placement pointer if this is a placement
|
||||
* `operator new` function.
|
||||
*/
|
||||
int getPlacementArgument() { none()}
|
||||
}
|
||||
|
||||
@@ -30,3 +30,11 @@ abstract class DeallocationExpr extends Expr {
|
||||
*/
|
||||
Expr getFreedExpr() { none() }
|
||||
}
|
||||
|
||||
/**
|
||||
* An `operator delete` or `operator delete[]` function that may be associated
|
||||
* with `delete` or `delete[]` expressions. Note that `delete` and `delete[]`
|
||||
* are not function calls, but these functions may also be called directly.
|
||||
*/
|
||||
abstract class OperatorDeleteDeallocationFunction extends DeallocationFunction {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user