Commit db602b81 authored by Martin Flöser's avatar Martin Flöser
Browse files

[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
parent b6122510
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment