From 7ce1810ccdf0b3974f2c9e8e4d5138a3945e329c Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Thu, 6 Sep 2018 15:59:31 -0700 Subject: [PATCH] ensure that timer period is non-negative --- rcl/include/rcl/timer.h | 3 ++- rcl/src/rcl/timer.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/rcl/include/rcl/timer.h b/rcl/include/rcl/timer.h index 0861b3775..7a57dfbcb 100644 --- a/rcl/include/rcl/timer.h +++ b/rcl/include/rcl/timer.h @@ -81,7 +81,8 @@ rcl_get_zero_initialized_timer(void); * The clock handle must be a pointer to an initialized rcl_clock_t struct. * The life time of the clock must exceed the life time of the timer. * - * The period is a duration (rather an absolute time in the future). + * The period is a non-negative duration (rather an absolute time in the + * future). * If the period is `0` then it will always be ready. * * The callback is an optional argument. diff --git a/rcl/src/rcl/timer.c b/rcl/src/rcl/timer.c index 087d40f31..447521088 100644 --- a/rcl/src/rcl/timer.c +++ b/rcl/src/rcl/timer.c @@ -60,6 +60,10 @@ rcl_timer_init( RCL_CHECK_ALLOCATOR_WITH_MSG(&allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(timer, RCL_RET_INVALID_ARGUMENT, allocator); RCL_CHECK_ARGUMENT_FOR_NULL(clock, RCL_RET_INVALID_ARGUMENT, allocator); + if (period < 0) { + RCL_SET_ERROR_MSG("timer period must be non-negative", allocator); + return RCL_RET_INVALID_ARGUMENT; + } RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Initializing timer with period: %" PRIu64 "ns", period) if (timer->impl) { RCL_SET_ERROR_MSG("timer already initailized, or memory was uninitialized", allocator);