mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
Merge pull request #5543 from MathiasVP/smart-ptr-like-class
C++: Add a class that models wrapped pointer types
This commit is contained in:
@@ -300,6 +300,14 @@ class FunctionCall extends Call, @funbindexpr {
|
||||
}
|
||||
}
|
||||
|
||||
/** A _user-defined_ unary `operator*` function. */
|
||||
class OverloadedPointerDereferenceFunction extends Function {
|
||||
OverloadedPointerDereferenceFunction() {
|
||||
this.hasName("operator*") and
|
||||
this.getEffectiveNumberOfParameters() = 1
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An instance of a _user-defined_ unary `operator*` applied to its argument.
|
||||
* ```
|
||||
@@ -309,8 +317,7 @@ class FunctionCall extends Call, @funbindexpr {
|
||||
*/
|
||||
class OverloadedPointerDereferenceExpr extends FunctionCall {
|
||||
OverloadedPointerDereferenceExpr() {
|
||||
getTarget().hasName("operator*") and
|
||||
getTarget().getEffectiveNumberOfParameters() = 1
|
||||
this.getTarget() instanceof OverloadedPointerDereferenceFunction
|
||||
}
|
||||
|
||||
override string getAPrimaryQlClass() { result = "OverloadedPointerDereferenceExpr" }
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import semmle.code.cpp.models.interfaces.Taint
|
||||
import semmle.code.cpp.models.interfaces.PointerWrapper
|
||||
|
||||
/**
|
||||
* The `std::shared_ptr` and `std::unique_ptr` template classes.
|
||||
*/
|
||||
private class UniqueOrSharedPtr extends Class {
|
||||
private class UniqueOrSharedPtr extends Class, PointerWrapper {
|
||||
UniqueOrSharedPtr() { this.hasQualifiedName(["std", "bsl"], ["shared_ptr", "unique_ptr"]) }
|
||||
|
||||
override MemberFunction getAnUnwrapperFunction() {
|
||||
result.(OverloadedPointerDereferenceFunction).getDeclaringType() = this
|
||||
or
|
||||
result.getClassAndName(["operator->", "get"]) = this
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/** Provides classes for modeling pointer wrapper types and expressions. */
|
||||
|
||||
private import cpp
|
||||
|
||||
/** A class that wraps a pointer type. For example, `std::unique_ptr` and `std::shared_ptr`. */
|
||||
abstract class PointerWrapper extends Class {
|
||||
/**
|
||||
* Gets a member function of this class that returns the wrapped pointer, if any.
|
||||
*
|
||||
* This includes both functions that return the wrapped pointer by value, and functions
|
||||
* that return a reference to the pointed-to object.
|
||||
*/
|
||||
abstract MemberFunction getAnUnwrapperFunction();
|
||||
}
|
||||
Reference in New Issue
Block a user