unix, windows: don't allow a NULL callback on timers

This commit is contained in:
Saúl Ibarra Corretgé 2014-09-04 14:17:59 +02:00
parent fb93ea4f17
commit 7ff52b836d
4 changed files with 19 additions and 0 deletions

View File

@ -65,6 +65,9 @@ int uv_timer_start(uv_timer_t* handle,
uint64_t repeat) {
uint64_t clamped_timeout;
if (cb == NULL)
return -EINVAL;
if (uv__is_active(handle))
uv_timer_stop(handle);

View File

@ -119,6 +119,9 @@ int uv_timer_start(uv_timer_t* handle, uv_timer_cb timer_cb, uint64_t timeout,
uv_loop_t* loop = handle->loop;
uv_timer_t* old;
if (timer_cb == NULL)
return UV_EINVAL;
if (handle->flags & UV_HANDLE_ACTIVE) {
RB_REMOVE(uv_timer_tree_s, &loop->timers, handle);
}

View File

@ -133,6 +133,7 @@ TEST_DECLARE (timer_huge_timeout)
TEST_DECLARE (timer_huge_repeat)
TEST_DECLARE (timer_run_once)
TEST_DECLARE (timer_from_check)
TEST_DECLARE (timer_null_callback)
TEST_DECLARE (idle_starvation)
TEST_DECLARE (loop_handles)
TEST_DECLARE (get_loadavg)
@ -451,6 +452,7 @@ TASK_LIST_START
TEST_ENTRY (timer_huge_repeat)
TEST_ENTRY (timer_run_once)
TEST_ENTRY (timer_from_check)
TEST_ENTRY (timer_null_callback)
TEST_ENTRY (idle_starvation)

View File

@ -290,3 +290,14 @@ TEST_IMPL(timer_run_once) {
MAKE_VALGRIND_HAPPY();
return 0;
}
TEST_IMPL(timer_null_callback) {
uv_timer_t handle;
ASSERT(0 == uv_timer_init(uv_default_loop(), &handle));
ASSERT(UV_EINVAL == uv_timer_start(&handle, NULL, 100, 100));
MAKE_VALGRIND_HAPPY();
return 0;
}