diff --git a/apps/plugins/lua/lauxlib.c b/apps/plugins/lua/lauxlib.c index b8332427f0..9a5939aff9 100644 --- a/apps/plugins/lua/lauxlib.c +++ b/apps/plugins/lua/lauxlib.c @@ -803,8 +803,10 @@ static int panic (lua_State *L) { LUALIB_API lua_State *luaL_newstate (void) { lua_State *L = lua_newstate(l_alloc, NULL); - lua_setallocf(L, l_alloc, L); /* allocator needs lua_State. */ - if (L) lua_atpanic(L, &panic); + if (L){ + lua_setallocf(L, l_alloc, L); /* allocator needs lua_State. */ + lua_atpanic(L, &panic); + } return L; } diff --git a/apps/plugins/lua/lmathlib.c b/apps/plugins/lua/lmathlib.c index 56c79afced..839d2014ad 100644 --- a/apps/plugins/lua/lmathlib.c +++ b/apps/plugins/lua/lmathlib.c @@ -96,7 +96,10 @@ static int math_floor (lua_State *L) { static int math_fmod (lua_State *L) { /* Was: lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); */ - lua_pushnumber(L, luaL_checknumber(L, 1) % luaL_checknumber(L, 2)); + lua_Number n = luaL_checknumber(L, 1); + lua_Number d = luaL_checknumber(L, 2); + luaL_argcheck(L, d != 0, 2, "division by zero"); + lua_pushnumber(L, n % d); return 1; } diff --git a/apps/plugins/lua/lparser.c b/apps/plugins/lua/lparser.c index 23d3972036..06c62cedde 100644 --- a/apps/plugins/lua/lparser.c +++ b/apps/plugins/lua/lparser.c @@ -359,6 +359,8 @@ static void open_func (LexState *ls, FuncState *fs) { static void close_func (LexState *ls) { + if (!ls || !ls->fs || !ls->fs->f) + return; lua_State *L = ls->L; FuncState *fs = ls->fs; Proto *f = fs->f;