summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixKey.c
diff options
context:
space:
mode:
authorChristian Werner <Christian.Werner@t-online.de>2018-06-03 22:03:05 (GMT)
committerChristian Werner <Christian.Werner@t-online.de>2018-06-03 22:03:05 (GMT)
commit5901ee19bfefd6e5e07bb534df0d2dfc8e71b9be (patch)
tree66d8d92939dc9065b1f073d514ad7d1e957d82b1 /unix/tkUnixKey.c
parent79700d14b1bb5505ca1b6c57c5887f4c3eac1138 (diff)
downloadtk-5901ee19bfefd6e5e07bb534df0d2dfc8e71b9be.zip
tk-5901ee19bfefd6e5e07bb534df0d2dfc8e71b9be.tar.gz
tk-5901ee19bfefd6e5e07bb534df0d2dfc8e71b9be.tar.bz2
Moved range check of keycode to TkpSetKeycodeAndState for ticket [382712ad].
Diffstat (limited to 'unix/tkUnixKey.c')
-rw-r--r--unix/tkUnixKey.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/unix/tkUnixKey.c b/unix/tkUnixKey.c
index c5a024f..6d4d0cf 100644
--- a/unix/tkUnixKey.c
+++ b/unix/tkUnixKey.c
@@ -110,7 +110,7 @@ TkpGetString(
XEvent *eventPtr, /* X keyboard event. */
Tcl_DString *dsPtr) /* Initialized, empty string to hold result. */
{
- int len, mincode, maxcode;
+ int len;
Tcl_DString buf;
TkKeyEvent *kePtr = (TkKeyEvent *) eventPtr;
@@ -136,27 +136,6 @@ TkpGetString(
goto done;
}
- /*
- * Filter keycodes out of range, otherwise
- * further Xlib function behavior might be undefined.
- */
-
- mincode = 0;
- maxcode = -1;
- XDisplayKeycodes(winPtr->dispPtr->display, &mincode, &maxcode);
- if ((eventPtr->xkey.keycode < mincode) ||
- (eventPtr->xkey.keycode > maxcode)) {
- if (eventPtr->xkey.keycode != 0) {
- len = 0;
- Tcl_DStringSetLength(dsPtr, len);
- goto done;
- }
- /*
- * Keycode 0 seems to come from e.g. ibus input methods,
- * we let this pass and hope for the best.
- */
- }
-
#ifdef TK_USE_INPUT_METHODS
if ((winPtr->dispPtr->flags & TK_DISPLAY_USE_IM)
&& (winPtr->inputContext != NULL)
@@ -269,7 +248,7 @@ TkpSetKeycodeAndState(
XEvent *eventPtr)
{
TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
- int state;
+ int state, mincode, maxcode;
KeyCode keycode;
if (keySym == NoSymbol) {
@@ -291,6 +270,21 @@ TkpSetKeycodeAndState(
}
}
}
+
+ /*
+ * Filter keycodes out of range, otherwise further Xlib function
+ * behavior might be undefined, in particular XIM could cause crashes.
+ */
+
+ mincode = 0;
+ maxcode = -1;
+ XDisplayKeycodes(dispPtr->display, &mincode, &maxcode);
+ if (keycode < mincode) {
+ keycode = mincode;
+ } else if (keycode > maxcode) {
+ keycode = maxcode;
+ }
+
eventPtr->xkey.keycode = keycode;
}