From 5bdf03798de8796eed20e842acfe498a4417af7f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 15 Dec 2022 13:30:02 -0300 Subject: XCB: use qOffsetStringArray This is the last string array I can see in qtbase sources for libraries (there are more in tests and qmake, which don't matter much). Pick-to: 6.4 6.5 Change-Id: I69ecc04064514f939896fffd1731046cebdfe3c9 Reviewed-by: Marc Mutz --- src/plugins/platforms/xcb/qxcbconnection_basic.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms/xcb') diff --git a/src/plugins/platforms/xcb/qxcbconnection_basic.cpp b/src/plugins/platforms/xcb/qxcbconnection_basic.cpp index 5f1b964afa..6416003bea 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_basic.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_basic.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qxcbconnection_basic.h" #include "qxcbbackingstore.h" // for createSystemVShmSegment() +#include "private/qoffsetstringarray_p.h" #include #include @@ -27,7 +28,7 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcQpaXcb, "qt.qpa.xcb") #if QT_CONFIG(xcb_xlib) -static const char * const xcbConnectionErrors[] = { +static constexpr auto xcbConnectionErrors = qOffsetStringArray( "No error", /* Error 0 */ "I/O error", /* XCB_CONN_ERROR */ "Unsupported extension used", /* XCB_CONN_CLOSED_EXT_NOTSUPPORTED */ @@ -36,7 +37,7 @@ static const char * const xcbConnectionErrors[] = { "Failed to parse display string", /* XCB_CONN_CLOSED_PARSE_ERR */ "No such screen on display", /* XCB_CONN_CLOSED_INVALID_SCREEN */ "Error during FD passing" /* XCB_CONN_CLOSED_FDPASSING_FAILED */ -}; +); static int nullErrorHandler(Display *dpy, XErrorEvent *err) { @@ -60,8 +61,7 @@ static int ioErrorHandler(Display *dpy) /* Print a message with a textual description of the error */ int code = xcb_connection_has_error(conn); const char *str = "Unknown error"; - int arrayLength = sizeof(xcbConnectionErrors) / sizeof(xcbConnectionErrors[0]); - if (code >= 0 && code < arrayLength) + if (code >= 0 && code < xcbConnectionErrors.count()) str = xcbConnectionErrors[code]; qWarning("The X11 connection broke: %s (code %d)", str, code); -- cgit v1.2.3