mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-02 01:47:41 +00:00
x11: Fix text input not being null-terminated
This commit is contained in:
parent
353001e077
commit
61c99c0da7
1 changed files with 5 additions and 3 deletions
|
@ -839,6 +839,7 @@ void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_
|
||||||
Display *display = videodata->display;
|
Display *display = videodata->display;
|
||||||
KeyCode keycode = xevent->xkey.keycode;
|
KeyCode keycode = xevent->xkey.keycode;
|
||||||
KeySym keysym = NoSymbol;
|
KeySym keysym = NoSymbol;
|
||||||
|
int text_length = 0;
|
||||||
char text[64];
|
char text[64];
|
||||||
Status status = 0;
|
Status status = 0;
|
||||||
SDL_bool handled_by_ime = SDL_FALSE;
|
SDL_bool handled_by_ime = SDL_FALSE;
|
||||||
|
@ -891,13 +892,13 @@ void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_
|
||||||
|
|
||||||
#ifdef X_HAVE_UTF8_STRING
|
#ifdef X_HAVE_UTF8_STRING
|
||||||
if (windowdata->ic && xevent->type == KeyPress) {
|
if (windowdata->ic && xevent->type == KeyPress) {
|
||||||
X11_Xutf8LookupString(windowdata->ic, &xevent->xkey, text, sizeof(text),
|
text_length = X11_Xutf8LookupString(windowdata->ic, &xevent->xkey, text, sizeof(text) - 1,
|
||||||
&keysym, &status);
|
&keysym, &status);
|
||||||
} else {
|
} else {
|
||||||
XLookupStringAsUTF8(&xevent->xkey, text, sizeof(text), &keysym, NULL);
|
text_length = XLookupStringAsUTF8(&xevent->xkey, text, sizeof(text) - 1, &keysym, NULL);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
XLookupStringAsUTF8(&xevent->xkey, text, sizeof(text), &keysym, NULL);
|
text_length = XLookupStringAsUTF8(&xevent->xkey, text, sizeof(text) - 1, &keysym, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SDL_USE_IME
|
#ifdef SDL_USE_IME
|
||||||
|
@ -912,6 +913,7 @@ void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_
|
||||||
SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, videodata->key_layout[keycode]);
|
SDL_SendKeyboardKey(0, keyboardID, SDL_PRESSED, videodata->key_layout[keycode]);
|
||||||
}
|
}
|
||||||
if (*text) {
|
if (*text) {
|
||||||
|
text[text_length] = '\0';
|
||||||
SDL_SendKeyboardText(text);
|
SDL_SendKeyboardText(text);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue