Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Palsson <karlp@etactica.com>2020-06-30 13:38:41 +0300
committerPetr Štetiar <ynezz@true.cz>2020-07-11 12:15:12 +0300
commit161c25960ba23e46ff960e84f25055f94758b909 (patch)
tree1fd1ac2f15d9fdda1ca682f8fbec780a36b7765a
parente85cb739766d00977a08cce98f161976da5fbefc (diff)
lua/uloop: fd_add() better args checking
Actually check for flags being valid, instead of simply ignoring the call if flags was zero. Use standard lua checks for the function argument, so you can get a normal "argument #2 was invalid, expected function, got xxx" instead of the vague, "invalid arg list" Signed-off-by: Karl Palsson <karlp@etactica.com>
-rw-r--r--lua/uloop.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/lua/uloop.c b/lua/uloop.c
index 1b0389f..fcbe274 100644
--- a/lua/uloop.c
+++ b/lua/uloop.c
@@ -232,17 +232,14 @@ static int ul_ufd_add(lua_State *L)
int ref;
int fd_ref;
- if (lua_isnumber(L, -1)) {
- flags = lua_tointeger(L, -1);
- lua_pop(L, 1);
- }
-
- if (!lua_isfunction(L, -1)) {
- lua_pushstring(L, "invalid arg list");
+ flags = luaL_checkinteger(L, -1);
+ if (!flags) {
+ lua_pushstring(L, "flags cannot be zero");
lua_error(L);
-
- return 0;
}
+ lua_pop(L, 1);
+
+ luaL_checktype(L, -1, LUA_TFUNCTION);
fd = get_sock_fd(L, -2);
@@ -261,8 +258,7 @@ static int ul_ufd_add(lua_State *L)
ufd->fd.fd = fd;
ufd->fd_r = fd_ref;
ufd->fd.cb = ul_ufd_cb;
- if (flags)
- uloop_fd_add(&ufd->fd, flags);
+ uloop_fd_add(&ufd->fd, flags);
return 1;
}