Skip to content

Commit

Permalink
ensure that timer period is non-negative (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas authored Sep 7, 2018
1 parent 16adb1e commit a0f83b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rcl/include/rcl/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions rcl/src/rcl/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a0f83b0

Please sign in to comment.