diff options
author | William Wilgus <wilgus.william@gmail.com> | 2021-08-13 22:36:52 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2021-08-13 22:44:45 -0400 |
commit | 8c36d8b131f2172ce8caaa20057af4d35b72c781 (patch) | |
tree | 0203ef4c4b5e4cdc037321a4ee16c4a8c04672ae | |
parent | aad15d5cd79a23d238a3cd3256001d61c46b8e50 (diff) | |
download | rockbox-8c36d8b131f2172ce8caaa20057af4d35b72c781.tar.gz rockbox-8c36d8b131f2172ce8caaa20057af4d35b72c781.zip |
lua Fix a few potential bugs
Change-Id: I0293371c58f1ca2d148b3b1e1f780cf76f312ef9
-rw-r--r-- | apps/plugins/lua/lauxlib.c | 6 | ||||
-rw-r--r-- | apps/plugins/lua/lmathlib.c | 5 | ||||
-rw-r--r-- | apps/plugins/lua/lparser.c | 2 |
3 files changed, 10 insertions, 3 deletions
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) { | |||
803 | 803 | ||
804 | LUALIB_API lua_State *luaL_newstate (void) { | 804 | LUALIB_API lua_State *luaL_newstate (void) { |
805 | lua_State *L = lua_newstate(l_alloc, NULL); | 805 | lua_State *L = lua_newstate(l_alloc, NULL); |
806 | lua_setallocf(L, l_alloc, L); /* allocator needs lua_State. */ | 806 | if (L){ |
807 | if (L) lua_atpanic(L, &panic); | 807 | lua_setallocf(L, l_alloc, L); /* allocator needs lua_State. */ |
808 | lua_atpanic(L, &panic); | ||
809 | } | ||
808 | return L; | 810 | return L; |
809 | } | 811 | } |
810 | 812 | ||
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) { | |||
96 | 96 | ||
97 | static int math_fmod (lua_State *L) { | 97 | static int math_fmod (lua_State *L) { |
98 | /* Was: lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); */ | 98 | /* Was: lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); */ |
99 | lua_pushnumber(L, luaL_checknumber(L, 1) % luaL_checknumber(L, 2)); | 99 | lua_Number n = luaL_checknumber(L, 1); |
100 | lua_Number d = luaL_checknumber(L, 2); | ||
101 | luaL_argcheck(L, d != 0, 2, "division by zero"); | ||
102 | lua_pushnumber(L, n % d); | ||
100 | return 1; | 103 | return 1; |
101 | } | 104 | } |
102 | 105 | ||
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) { | |||
359 | 359 | ||
360 | 360 | ||
361 | static void close_func (LexState *ls) { | 361 | static void close_func (LexState *ls) { |
362 | if (!ls || !ls->fs || !ls->fs->f) | ||
363 | return; | ||
362 | lua_State *L = ls->L; | 364 | lua_State *L = ls->L; |
363 | FuncState *fs = ls->fs; | 365 | FuncState *fs = ls->fs; |
364 | Proto *f = fs->f; | 366 | Proto *f = fs->f; |