mirror of
https://github.com/Ryujinx/SDL.git
synced 2025-01-23 14:31:06 +00:00
Fixed infinite loop when SDL_SendKeyboardText() is passed invalid UTF-8 text
This commit is contained in:
parent
954bbdf3ae
commit
0cd5b08bfe
|
@ -914,12 +914,16 @@ SDL_SendKeyboardText(const char *text)
|
||||||
posted = 0;
|
posted = 0;
|
||||||
if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) {
|
if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
size_t i = 0, length = SDL_strlen(text);
|
size_t pos = 0, advance, length = SDL_strlen(text);
|
||||||
|
|
||||||
event.text.type = SDL_TEXTINPUT;
|
event.text.type = SDL_TEXTINPUT;
|
||||||
event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
|
event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
|
||||||
while (i < length) {
|
while (pos < length) {
|
||||||
i += SDL_utf8strlcpy(event.text.text, text + i, SDL_arraysize(event.text.text));
|
advance = SDL_utf8strlcpy(event.text.text, text + pos, SDL_arraysize(event.text.text));
|
||||||
|
if (!advance) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pos += advance;
|
||||||
posted |= (SDL_PushEvent(&event) > 0);
|
posted |= (SDL_PushEvent(&event) > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue