Browse files

prepare/idle/check: don't allow NULL callback

  • Loading branch information...
1 parent 5af43ba commit 33d5c497a6fdd0815144ff61f3d28f33281a11ba @saghul saghul committed with bnoordhuis Nov 30, 2012
Showing with 14 additions and 4 deletions.
  1. +3 −1 src/unix/loop-watcher.c
  2. +3 −0 src/win/loop-watcher.c
  3. +8 −3 test/test-ref.c
View
4 src/unix/loop-watcher.c
@@ -31,6 +31,8 @@
\
int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \
if (uv__is_active(handle)) return 0; \
+ if (cb == NULL) \
+ return uv__set_artificial_error(handle->loop, UV_EINVAL); \
ngx_queue_insert_head(&handle->loop->name##_handles, &handle->queue); \
handle->name##_cb = cb; \
uv__handle_start(handle); \
@@ -49,7 +51,7 @@
ngx_queue_t* q; \
ngx_queue_foreach(q, &loop->name##_handles) { \
h = ngx_queue_data(q, uv_##name##_t, queue); \
- if (h->name##_cb) h->name##_cb(h, 0); \
+ h->name##_cb(h, 0); \
} \
} \
\
View
3 src/win/loop-watcher.c
@@ -52,6 +52,9 @@ void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) {
if (handle->flags & UV_HANDLE_ACTIVE) \
return 0; \
\
+ if (cb == NULL) \
+ return uv__set_artificial_error(handle->loop, UV_EINVAL); \
+ \
old_head = loop->name##_handles; \
\
handle->name##_next = old_head; \
View
11 test/test-ref.c
@@ -58,6 +58,11 @@ static void fail_cb(void) {
}
+static void fail_cb2() {
+ ASSERT(0 && "fail_cb2 should not have been called");
+}
+
+
static void req_cb(uv_handle_t* req, int status) {
req_cb_called++;
}
@@ -104,7 +109,7 @@ TEST_IMPL(ref) {
TEST_IMPL(idle_ref) {
uv_idle_t h;
uv_idle_init(uv_default_loop(), &h);
- uv_idle_start(&h, NULL);
+ uv_idle_start(&h, fail_cb2);
uv_unref((uv_handle_t*)&h);
uv_run(uv_default_loop());
do_close(&h);
@@ -127,7 +132,7 @@ TEST_IMPL(async_ref) {
TEST_IMPL(prepare_ref) {
uv_prepare_t h;
uv_prepare_init(uv_default_loop(), &h);
- uv_prepare_start(&h, NULL);
+ uv_prepare_start(&h, fail_cb2);
uv_unref((uv_handle_t*)&h);
uv_run(uv_default_loop());
do_close(&h);
@@ -139,7 +144,7 @@ TEST_IMPL(prepare_ref) {
TEST_IMPL(check_ref) {
uv_check_t h;
uv_check_init(uv_default_loop(), &h);
- uv_check_start(&h, NULL);
+ uv_check_start(&h, fail_cb2);
uv_unref((uv_handle_t*)&h);
uv_run(uv_default_loop());
do_close(&h);

0 comments on commit 33d5c49

Please sign in to comment.