mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-28 08:48:43 +00:00
keyboard: Limit text input event size for sdl2-compat
This commit is contained in:
parent
8ee03d68bd
commit
32f460d357
1 changed files with 26 additions and 4 deletions
|
|
@ -784,11 +784,33 @@ void SDL_SendKeyboardText(const char *text)
|
|||
event.type = SDL_EVENT_TEXT_INPUT;
|
||||
event.common.timestamp = 0;
|
||||
event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
|
||||
event.text.text = SDL_CreateTemporaryString(text);
|
||||
if (!event.text.text) {
|
||||
return;
|
||||
|
||||
if (SDL_GetHintBoolean("SDL2_COMPAT", false)) {
|
||||
size_t pos = 0, advance, length = SDL_strlen(text);
|
||||
|
||||
// Limit SDL_EVENT_TEXT_INPUT events to 32 bytes for SDL2 compatibility
|
||||
while (pos < length) {
|
||||
char trimmed_text[32];
|
||||
|
||||
advance = SDL_utf8strlcpy(trimmed_text, text + pos, SDL_arraysize(trimmed_text));
|
||||
if (!advance) {
|
||||
break;
|
||||
}
|
||||
pos += advance;
|
||||
|
||||
event.text.text = SDL_CreateTemporaryString(trimmed_text);
|
||||
if (!event.text.text) {
|
||||
return;
|
||||
}
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
} else {
|
||||
event.text.text = SDL_CreateTemporaryString(text);
|
||||
if (!event.text.text) {
|
||||
return;
|
||||
}
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue