summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/xcb/qxcbkeyboard.cpp
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2015-04-16 17:43:46 +0200
committerKonstantin Ritt <ritt.ks@gmail.com>2015-04-17 01:08:49 +0000
commit7f82b9258e702fcc1857814c585b1b89d9328006 (patch)
tree82b0b3e7fad781255552eb4ece06918324f6a66c /src/plugins/platforms/xcb/qxcbkeyboard.cpp
parenta7303e45dbd1ac37048fb1a907edabe0158b2b52 (diff)
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 <marc.mutz@kdab.com> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'src/plugins/platforms/xcb/qxcbkeyboard.cpp')
-rw-r--r--src/plugins/platforms/xcb/qxcbkeyboard.cpp4
1 files changed, 2 insertions, 2 deletions
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)