mirror of
https://github.com/github/codeql.git
synced 2025-12-18 09:43:15 +01:00
The `Expr.getType` predicate returns a pointer type since that's the type of the `new`-expression as a whole. To find the class type, we use `NewExpr.getAllocatedType`. This commit reduces the number of alerts in a Qt snapshot from 229 to 51, and it removes the two false positives in https://github.com/Subsurface-divelog/subsurface.
26 lines
743 B
C++
26 lines
743 B
C++
struct QObject {
|
|
QObject(QObject *parent);
|
|
void setParent(QObject *parent);
|
|
};
|
|
|
|
struct DerivedFromQObject : public QObject {
|
|
DerivedFromQObject(QObject *parent);
|
|
};
|
|
|
|
class MyQtUser {
|
|
DerivedFromQObject *noParent, *constructorParent, *laterParent;
|
|
|
|
MyQtUser(QObject *parent) {
|
|
// This object sets its parent pointer to null and thus must be deleted
|
|
// manually.
|
|
noParent = new DerivedFromQObject(nullptr); // BAD [NOT DETECTED]
|
|
|
|
// This object does not need to be deleted because it will be deleted by
|
|
// its parent object when the time is right.
|
|
constructorParent = new DerivedFromQObject(parent); // GOOD
|
|
|
|
laterParent = new DerivedFromQObject(nullptr); // GOOD
|
|
laterParent->setParent(parent);
|
|
}
|
|
};
|