Commit 07fc1bb883f4c3d9b603d3a3be8c0f2dfa88c285

Ankith 2021-03-15T15:10:49

Fix invalid UTF-8 handling of extra bytes

diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c
index c0a541d..7eb8bde 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;
 }