Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit 21c81ca

Browse files
committed
+ Fix lua API in 5.1 or upper
+ Fix UB when pass a negative number into `isprint()` when using UTF-8 charators.(Which will crash with MSVC) + Fix `cannot convert ‘bool’ to ‘const char*’ in return` or something like this with new GCC and clang. Signed-off-by: owent <admin@owent.net>
1 parent 56a7708 commit 21c81ca

4 files changed

Lines changed: 16 additions & 2 deletions

File tree

lua/def.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,11 @@ const upb_FileDef* lupb_FileDef_check(lua_State* L, int narg) {
617617

618618
static int lupb_FileDef_Dependency(lua_State* L) {
619619
const upb_FileDef* f = lupb_FileDef_check(L, 1);
620+
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
621+
int index = luaL_checkinteger(L, 2);
622+
#else
620623
int index = luaL_checkint(L, 2);
624+
#endif
621625
const upb_FileDef* dep = upb_FileDef_Dependency(f, index);
622626
lupb_wrapper_pushwrapper(L, 1, dep, LUPB_FILEDEF);
623627
return 1;
@@ -631,7 +635,11 @@ static int lupb_FileDef_DependencyCount(lua_State* L) {
631635

632636
static int lupb_FileDef_enum(lua_State* L) {
633637
const upb_FileDef* f = lupb_FileDef_check(L, 1);
638+
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
639+
int index = luaL_checkinteger(L, 2);
640+
#else
634641
int index = luaL_checkint(L, 2);
642+
#endif
635643
const upb_EnumDef* e = upb_FileDef_TopLevelEnum(f, index);
636644
lupb_wrapper_pushwrapper(L, 1, e, LUPB_ENUMDEF);
637645
return 1;
@@ -645,7 +653,11 @@ static int lupb_FileDef_enumcount(lua_State* L) {
645653

646654
static int lupb_FileDef_msg(lua_State* L) {
647655
const upb_FileDef* f = lupb_FileDef_check(L, 1);
656+
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
657+
int index = luaL_checkinteger(L, 2);
658+
#else
648659
int index = luaL_checkint(L, 2);
660+
#endif
649661
const upb_MessageDef* m = upb_FileDef_TopLevelMessage(f, index);
650662
lupb_wrapper_pushwrapper(L, 1, m, LUPB_MSGDEF);
651663
return 1;

lua/upb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@
6161
/* Lua compatibility code *****************************************************/
6262

6363
/* Shims for upcoming Lua 5.3 functionality. */
64+
#if LUA_VERSION_NUM < 503
6465
static bool lua_isinteger(lua_State* L, int argn) {
6566
LUPB_UNUSED(L);
6667
LUPB_UNUSED(argn);
6768
return false;
6869
}
70+
#endif
6971

7072
/* Utility functions **********************************************************/
7173

lua/upbc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void PrintString(int max_cols, absl::string_view* str,
7979
} else if (ch == '\'') {
8080
printer->PrintRaw("\\'");
8181
max_cols--;
82-
} else if (isprint(ch)) {
82+
} else if (isprint(static_cast<int>(static_cast<unsigned char>(ch)))) {
8383
printer->WriteRaw(&ch, 1);
8484
max_cols--;
8585
} else {

upb/text/encode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static void txtenc_map(txtenc* e, const upb_Map* map, const upb_FieldDef* f) {
308308
#define CHK(x) \
309309
do { \
310310
if (!(x)) { \
311-
return false; \
311+
return NULL; \
312312
} \
313313
} while (0)
314314

0 commit comments

Comments
 (0)