use xcb_connection_has_error to check for failue

xcb_connectxx() always returns a non-NULL pointer to a
xcb_connection_t, even on failure.


(cherry picked from commit c5185611a5)

Co-authored-by: Xiao YaoBing <xiaoyaobing@uniontech.com>
wilder/Plasma/6.2
Vlad Zahorodnii 1 year ago
parent 2dd3388223
commit 4997eedf5c
  1. 3
      src/backends/x11/windowed/x11_windowed_backend.cpp
  2. 5
      tests/normalhintsbasesizetest.cpp
  3. 6
      tests/pointerconstraintstest.cpp

@ -172,7 +172,8 @@ X11WindowedBackend::~X11WindowedBackend()
bool X11WindowedBackend::initialize() bool X11WindowedBackend::initialize()
{ {
m_connection = xcb_connect(m_options.display.toLatin1(), &m_screenNumber); m_connection = xcb_connect(m_options.display.toLatin1(), &m_screenNumber);
if (!m_connection) { if (xcb_connection_has_error(m_connection)) {
xcb_disconnect(m_connection);
return false; return false;
} }

@ -34,6 +34,11 @@ int main(int, char **)
int screenNumber; int screenNumber;
xcb_connection_t *c = xcb_connect(nullptr, &screenNumber); xcb_connection_t *c = xcb_connect(nullptr, &screenNumber);
if (xcb_connection_has_error(c)) {
xcb_disconnect(c);
return 1;
}
auto getScreen = [=]() { auto getScreen = [=]() {
const xcb_setup_t *setup = xcb_get_setup(c); const xcb_setup_t *setup = xcb_get_setup(c);
auto it = xcb_setup_roots_iterator(setup); auto it = xcb_setup_roots_iterator(setup);

@ -240,8 +240,10 @@ void XBackend::init(QQuickView *view)
{ {
Backend::init(view); Backend::init(view);
m_xcbConn = xcb_connect(nullptr, nullptr); m_xcbConn = xcb_connect(nullptr, nullptr);
if (!m_xcbConn) {
qDebug() << "Could not open XCB connection."; if (xcb_connection_has_error(m_xcbConn)) {
xcb_disconnect(m_xcbConn);
qFatal() << "Could not open XCB connection.";
} }
} }

Loading…
Cancel
Save