Skip to content

Commit

Permalink
Fix luv_check_* to actually check for valid structs
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Nov 3, 2014
1 parent 9d5fbb3 commit e02ef82
Show file tree
Hide file tree
Showing 18 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/async.c
Expand Up @@ -18,7 +18,7 @@

static uv_async_t* luv_check_async(lua_State* L, int index) {
uv_async_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_ASYNC, index, "Expected uv_async_t");
luaL_argcheck(L, handle->type == UV_ASYNC && handle->data, index, "Expected uv_async_t");
return handle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/check.c
Expand Up @@ -18,7 +18,7 @@

static uv_check_t* luv_check_check(lua_State* L, int index) {
uv_check_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_CHECK, index, "Expected uv_check_t");
luaL_argcheck(L, handle->type == UV_CHECK && handle->data, index, "Expected uv_check_t");
return handle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/fs.c
Expand Up @@ -19,7 +19,7 @@

static uv_fs_t* luv_check_fs(lua_State* L, int index) {
uv_fs_t* req = luaL_checkudata(L, index, "uv_req");
luaL_argcheck(L, req->type = UV_FS, index, "Expected uv_fs_t");
luaL_argcheck(L, req->type = UV_FS && req->data, index, "Expected uv_fs_t");
return req;
}

Expand Down
2 changes: 1 addition & 1 deletion src/fs_event.c
Expand Up @@ -19,7 +19,7 @@

static uv_fs_event_t* luv_check_fs_event(lua_State* L, int index) {
uv_fs_event_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_FS_EVENT, index, "Expected uv_fs_event_t");
luaL_argcheck(L, handle->type == UV_FS_EVENT && handle->data, index, "Expected uv_fs_event_t");
return handle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/fs_poll.c
Expand Up @@ -19,7 +19,7 @@

static uv_fs_poll_t* luv_check_fs_poll(lua_State* L, int index) {
uv_fs_poll_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_FS_POLL, index, "Expected uv_fs_poll_t");
luaL_argcheck(L, handle->type == UV_FS_POLL && handle->data, index, "Expected uv_fs_poll_t");
return handle;
}

Expand Down
4 changes: 3 additions & 1 deletion src/handle.c
Expand Up @@ -17,7 +17,9 @@
#include "luv.h"

static uv_handle_t* luv_check_handle(lua_State* L, int index) {
return luaL_checkudata(L, index, "uv_handle");
uv_handle_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->data, index, "Expected uv_handle_t");
return handle;
}

// Show the libuv type instead of generic "userdata"
Expand Down
2 changes: 1 addition & 1 deletion src/idle.c
Expand Up @@ -18,7 +18,7 @@

static uv_idle_t* luv_check_idle(lua_State* L, int index) {
uv_idle_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_IDLE, index, "Expected uv_idle_t");
luaL_argcheck(L, handle->type == UV_IDLE && handle->data, index, "Expected uv_idle_t");
return handle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pipe.c
Expand Up @@ -18,7 +18,7 @@

static uv_pipe_t* luv_check_pipe(lua_State* L, int index) {
uv_pipe_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_NAMED_PIPE, index, "Expected uv_pipe_t");
luaL_argcheck(L, handle->type == UV_NAMED_PIPE && handle->data, index, "Expected uv_pipe_t");
return handle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/poll.c
Expand Up @@ -18,7 +18,7 @@

static uv_poll_t* luv_check_poll(lua_State* L, int index) {
uv_poll_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_POLL, index, "Expected uv_poll_t");
luaL_argcheck(L, handle->type == UV_POLL && handle->data, index, "Expected uv_poll_t");
return handle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/prepare.c
Expand Up @@ -18,7 +18,7 @@

static uv_prepare_t* luv_check_prepare(lua_State* L, int index) {
uv_prepare_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_PREPARE, index, "Expected uv_prepare_t");
luaL_argcheck(L, handle->type == UV_PREPARE && handle->data, index, "Expected uv_prepare_t");
return handle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/process.c
Expand Up @@ -23,7 +23,7 @@ static int luv_disable_stdio_inheritance(lua_State* L) {

static uv_process_t* luv_check_process(lua_State* L, int index) {
uv_process_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_PROCESS, index, "Expected uv_process_t");
luaL_argcheck(L, handle->type == UV_PROCESS && handle->data, index, "Expected uv_process_t");
return handle;
}

Expand Down
4 changes: 3 additions & 1 deletion src/req.c
Expand Up @@ -17,7 +17,9 @@
#include "luv.h"

static uv_req_t* luv_check_req(lua_State* L, int index) {
return luaL_checkudata(L, index, "uv_req");
uv_req_t* req = luaL_checkudata(L, index, "uv_req");
luaL_argcheck(L, req->data, index, "Expected uv_req_t");
return req;
}

static int luv_req_tostring(lua_State* L) {
Expand Down
2 changes: 1 addition & 1 deletion src/signal.c
Expand Up @@ -50,7 +50,7 @@ static int luv_string_to_signal(const char* string) {

static uv_signal_t* luv_check_signal(lua_State* L, int index) {
uv_signal_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_SIGNAL, index, "Expected uv_signal_t");
luaL_argcheck(L, handle->type == UV_SIGNAL && handle->data, index, "Expected uv_signal_t");
return handle;
}

Expand Down
4 changes: 2 additions & 2 deletions src/stream.c
Expand Up @@ -18,10 +18,10 @@

static uv_stream_t* luv_check_stream(lua_State* L, int index) {
uv_stream_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L,
luaL_argcheck(L, handle->data && (
handle->type == UV_TCP ||
handle->type == UV_TTY ||
handle->type == UV_NAMED_PIPE,
handle->type == UV_NAMED_PIPE),
index, "uv_stream_t subclass required");
return handle;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tcp.c
Expand Up @@ -18,7 +18,7 @@

static uv_tcp_t* luv_check_tcp(lua_State* L, int index) {
uv_tcp_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_TCP, index, "Expected uv_tcp_t");
luaL_argcheck(L, handle->type == UV_TCP && handle->data, index, "Expected uv_tcp_t");
return handle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/timer.c
Expand Up @@ -18,7 +18,7 @@

static uv_timer_t* luv_check_timer(lua_State* L, int index) {
uv_timer_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_TIMER, index, "Expected uv_timer_t");
luaL_argcheck(L, handle->type == UV_TIMER && handle->data, index, "Expected uv_timer_t");
return handle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/tty.c
Expand Up @@ -18,7 +18,7 @@

static uv_tty_t* luv_check_tty(lua_State* L, int index) {
uv_tty_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_TTY, index, "Expected uv_tty_t");
luaL_argcheck(L, handle->type == UV_TTY && handle->data, index, "Expected uv_tty_t");
return handle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/udp.c
Expand Up @@ -18,7 +18,7 @@

static uv_udp_t* luv_check_udp(lua_State* L, int index) {
uv_udp_t* handle = luaL_checkudata(L, index, "uv_handle");
luaL_argcheck(L, handle->type = UV_UDP, index, "Expected uv_udp_t");
luaL_argcheck(L, handle->type == UV_UDP && handle->data, index, "Expected uv_udp_t");
return handle;
}

Expand Down

0 comments on commit e02ef82

Please sign in to comment.