[server] Ensure that Resource::Private::get returns nullptr if passed a nullptr
Summary: A Resource might be unbound, but not yet destroyed. In that case this return a Resource instead of nullptr. This change adds an explicit nullptr check. Reviewers: #plasma_on_wayland Subscribers: plasma-devel Tags: #plasma_on_wayland Differential Revision: https://phabricator.kde.org/D1938
This commit is contained in:
parent
b612251015
commit
db602b8188
2 changed files with 10 additions and 0 deletions
|
@ -178,6 +178,8 @@ void TestWaylandSurface::testStaticAccessor()
|
|||
QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*)));
|
||||
QVERIFY(serverSurfaceCreated.isValid());
|
||||
|
||||
QVERIFY(!KWayland::Server::SurfaceInterface::get(nullptr));
|
||||
QVERIFY(!KWayland::Server::SurfaceInterface::get(1, nullptr));
|
||||
QVERIFY(KWayland::Client::Surface::all().isEmpty());
|
||||
KWayland::Client::Surface *s1 = m_compositor->createSurface();
|
||||
QVERIFY(s1->isValid());
|
||||
|
@ -226,6 +228,11 @@ void TestWaylandSurface::testStaticAccessor()
|
|||
delete s1;
|
||||
QVERIFY(KWayland::Client::Surface::all().isEmpty());
|
||||
QVERIFY(!KWayland::Client::Surface::get(nullptr));
|
||||
QSignalSpy unboundSpy(serverSurface1, &KWayland::Server::Resource::unbound);
|
||||
QVERIFY(unboundSpy.isValid());
|
||||
QVERIFY(unboundSpy.wait());
|
||||
QVERIFY(!KWayland::Server::SurfaceInterface::get(nullptr));
|
||||
QVERIFY(!KWayland::Server::SurfaceInterface::get(1, nullptr));
|
||||
}
|
||||
|
||||
void TestWaylandSurface::testDamage()
|
||||
|
|
|
@ -44,6 +44,9 @@ public:
|
|||
static ResourceDerived *get(wl_resource *native) {
|
||||
static_assert(std::is_base_of<Resource, ResourceDerived>::value,
|
||||
"ResourceDerived must be derived from Resource");
|
||||
if (!native) {
|
||||
return nullptr;
|
||||
}
|
||||
auto it = std::find_if(s_allResources.constBegin(), s_allResources.constEnd(),
|
||||
[native](Private *p) {
|
||||
return p->resource == native;
|
||||
|
|
Loading…
Reference in a new issue