From 7f82b9258e702fcc1857814c585b1b89d9328006 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 16 Apr 2015 17:43:46 +0200 Subject: Ensure the UTF-8 string for a xcb_keycode_t has the correct length. On my platform (Archlinux, libxcb 1.11-1) and a recent build of Qt dev I noticed that writing anything to a QLineEdit was broken, as not only the character for the pressed key was inserted, but also what looks like whitespace. A simple debug program showed that a "\u0000" is appended to every character in the QString text associated with a QKeyEvent, which brought me to QXcbKeyboard::lookupString. The QByteArray to QString conversion using QString::fromUtf8 includes the \x00 byte at the end of the buffer. By leveraging the size returned by the xcb API and passing that to QString::fromUtf8 we can prevent this problem from arising. Change-Id: Ic1d4390e4154e9ed729cd23286811d6eecdf54f6 Reviewed-by: Marc Mutz Reviewed-by: Konstantin Ritt --- src/plugins/platforms/xcb/qxcbkeyboard.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/xcb/qxcbkeyboard.cpp') diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.cpp b/src/plugins/platforms/xcb/qxcbkeyboard.cpp index 376599578f..3b356525e3 100644 --- a/src/plugins/platforms/xcb/qxcbkeyboard.cpp +++ b/src/plugins/platforms/xcb/qxcbkeyboard.cpp @@ -1518,8 +1518,8 @@ QString QXcbKeyboard::lookupString(struct xkb_state *state, xcb_keycode_t code) QByteArray chars; chars.resize(1 + xkb_state_key_get_utf8(state, code, 0, 0)); // equivalent of XLookupString - xkb_state_key_get_utf8(state, code, chars.data(), chars.size()); - return QString::fromUtf8(chars); + const int size = xkb_state_key_get_utf8(state, code, chars.data(), chars.size()); + return QString::fromUtf8(chars.constData(), size); } void QXcbKeyboard::handleKeyPressEvent(const xcb_key_press_event_t *event) -- cgit v1.2.3