From 07fc1bb883f4c3d9b603d3a3be8c0f2dfa88c285 Mon Sep 17 00:00:00 2001 From: Ankith <46915066+ankith26@users.noreply.github.com> Date: Mon, 15 Mar 2021 15:10:49 +0530 Subject: [PATCH] Fix invalid UTF-8 handling of extra bytes --- src/events/SDL_keyboard.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index c0a541ded..7eb8bde8a 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -537,27 +537,12 @@ SDL_UCS4ToUTF8(Uint32 ch, char *dst) p[1] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); p[2] = 0x80 | (Uint8) (ch & 0x3F); dst += 3; - } else if (ch <= 0x1FFFFF) { + } else { p[0] = 0xF0 | (Uint8) ((ch >> 18) & 0x07); p[1] = 0x80 | (Uint8) ((ch >> 12) & 0x3F); p[2] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); p[3] = 0x80 | (Uint8) (ch & 0x3F); dst += 4; - } else if (ch <= 0x3FFFFFF) { - p[0] = 0xF8 | (Uint8) ((ch >> 24) & 0x03); - p[1] = 0x80 | (Uint8) ((ch >> 18) & 0x3F); - p[2] = 0x80 | (Uint8) ((ch >> 12) & 0x3F); - p[3] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); - p[4] = 0x80 | (Uint8) (ch & 0x3F); - dst += 5; - } else { - p[0] = 0xFC | (Uint8) ((ch >> 30) & 0x01); - p[1] = 0x80 | (Uint8) ((ch >> 24) & 0x3F); - p[2] = 0x80 | (Uint8) ((ch >> 18) & 0x3F); - p[3] = 0x80 | (Uint8) ((ch >> 12) & 0x3F); - p[4] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); - p[5] = 0x80 | (Uint8) (ch & 0x3F); - dst += 6; } return dst; }