From f1a4029743ca095025e852b3859212508c9de74e Mon Sep 17 00:00:00 2001 From: Philippe Verdy <1387035+verdy-p@users.noreply.github.com> Date: Sat, 13 Jun 2020 04:25:23 +0200 Subject: [PATCH] fix invalid codePoint=0x110000 in icu_utf8_char() --- src/icu.utf8.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/icu.utf8.c b/src/icu.utf8.c index 40a2ebd..8f64ce9 100644 --- a/src/icu.utf8.c +++ b/src/icu.utf8.c @@ -365,10 +365,7 @@ static int icu_utf8_char(lua_State *L) { luaL_addchar(&buf, (char)(0x80 | ((codePoint >> 6) & 0x3F))); luaL_addchar(&buf, (char)(0x80 | (codePoint & 0x3F))); } - else if (codePoint > 0x110000) { - return luaL_argerror(L,i+1,"invalid codepoint"); - } - else { + else if (codePoint < 0x110000) { // 00000000 000zzzzz yyyyyyyy xxxxxxxx // 11110zzz 10zzyyyy 10yyyyxx 10xxxxxx luaL_addchar(&buf, (char)(0xF0 | (codePoint >> 18))); @@ -376,6 +373,9 @@ static int icu_utf8_char(lua_State *L) { luaL_addchar(&buf, (char)(0x80 | ((codePoint >> 6) & 0x3F))); luaL_addchar(&buf, (char)(0x80 | (codePoint & 0x3F))); } + else { + return luaL_argerror(L,i+1,"invalid codepoint"); + } } luaL_pushresult(&buf); return 1;