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 1bd316940..ccad04739 100644 --- a/rcl/src/rcl/timer.c +++ b/rcl/src/rcl/timer.c @@ -62,6 +62,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);