From 21c81ca51d73c342f650e1a7c5292eb9a0bdb7ee Mon Sep 17 00:00:00 2001 From: owent Date: Mon, 12 Jun 2023 10:36:48 +0800 Subject: [PATCH] =?UTF-8?q?+=20Fix=20lua=20API=20in=205.1=20or=20upper=20+?= =?UTF-8?q?=20Fix=20UB=20when=20pass=20a=20negative=20number=20into=20`isp?= =?UTF-8?q?rint()`=20when=20using=20UTF-8=20charators.(Which=20will=20cras?= =?UTF-8?q?h=20with=20MSVC)=20+=20Fix=20`cannot=20convert=20=E2=80=98bool?= =?UTF-8?q?=E2=80=99=20to=20=E2=80=98const=20char*=E2=80=99=20in=20return`?= =?UTF-8?q?=20or=20something=20like=20this=20with=20new=20GCC=20and=20clan?= =?UTF-8?q?g.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: owent --- lua/def.c | 12 ++++++++++++ lua/upb.c | 2 ++ lua/upbc.cc | 2 +- upb/text/encode.c | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lua/def.c b/lua/def.c index 90161ec819..a7a26c89c0 100644 --- a/lua/def.c +++ b/lua/def.c @@ -617,7 +617,11 @@ const upb_FileDef* lupb_FileDef_check(lua_State* L, int narg) { static int lupb_FileDef_Dependency(lua_State* L) { const upb_FileDef* f = lupb_FileDef_check(L, 1); +#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501 + int index = luaL_checkinteger(L, 2); +#else int index = luaL_checkint(L, 2); +#endif const upb_FileDef* dep = upb_FileDef_Dependency(f, index); lupb_wrapper_pushwrapper(L, 1, dep, LUPB_FILEDEF); return 1; @@ -631,7 +635,11 @@ static int lupb_FileDef_DependencyCount(lua_State* L) { static int lupb_FileDef_enum(lua_State* L) { const upb_FileDef* f = lupb_FileDef_check(L, 1); +#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501 + int index = luaL_checkinteger(L, 2); +#else int index = luaL_checkint(L, 2); +#endif const upb_EnumDef* e = upb_FileDef_TopLevelEnum(f, index); lupb_wrapper_pushwrapper(L, 1, e, LUPB_ENUMDEF); return 1; @@ -645,7 +653,11 @@ static int lupb_FileDef_enumcount(lua_State* L) { static int lupb_FileDef_msg(lua_State* L) { const upb_FileDef* f = lupb_FileDef_check(L, 1); +#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501 + int index = luaL_checkinteger(L, 2); +#else int index = luaL_checkint(L, 2); +#endif const upb_MessageDef* m = upb_FileDef_TopLevelMessage(f, index); lupb_wrapper_pushwrapper(L, 1, m, LUPB_MSGDEF); return 1; diff --git a/lua/upb.c b/lua/upb.c index 8c73e5fb7f..f6ff01114d 100644 --- a/lua/upb.c +++ b/lua/upb.c @@ -61,11 +61,13 @@ /* Lua compatibility code *****************************************************/ /* Shims for upcoming Lua 5.3 functionality. */ +#if LUA_VERSION_NUM < 503 static bool lua_isinteger(lua_State* L, int argn) { LUPB_UNUSED(L); LUPB_UNUSED(argn); return false; } +#endif /* Utility functions **********************************************************/ diff --git a/lua/upbc.cc b/lua/upbc.cc index e857f7aae9..8efb491d0e 100644 --- a/lua/upbc.cc +++ b/lua/upbc.cc @@ -79,7 +79,7 @@ static void PrintString(int max_cols, absl::string_view* str, } else if (ch == '\'') { printer->PrintRaw("\\'"); max_cols--; - } else if (isprint(ch)) { + } else if (isprint(static_cast(static_cast(ch)))) { printer->WriteRaw(&ch, 1); max_cols--; } else { diff --git a/upb/text/encode.c b/upb/text/encode.c index c694088fc2..33438be30b 100644 --- a/upb/text/encode.c +++ b/upb/text/encode.c @@ -308,7 +308,7 @@ static void txtenc_map(txtenc* e, const upb_Map* map, const upb_FieldDef* f) { #define CHK(x) \ do { \ if (!(x)) { \ - return false; \ + return NULL; \ } \ } while (0)