Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rcl/include/rcl/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ extern "C"
#include "rcl/types.h"
#include "rcl/visibility_control.h"

#define RCL_S_TO_NS(seconds) (seconds * (1000 * 1000 * 1000))
#define RCL_MS_TO_NS(milliseconds) (milliseconds * (1000 * 1000))
#define RCL_US_TO_NS(microseconds) (microseconds * 1000)
#define RCL_S_TO_NS(seconds) ((int64_t)seconds * (1000 * 1000 * 1000))
#define RCL_MS_TO_NS(milliseconds) ((int64_t)milliseconds * (1000 * 1000))
#define RCL_US_TO_NS(microseconds) ((int64_t)microseconds * 1000)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this mean this macro now can't be used properly with uint64_ts e.g. rcl_time_point_value_t?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question, I didn't see any part of the codebase using it for anything else than for rcl_wait that uses int64_t that's why I went for it.
I would naively assume that an implicit cast from int64_t to uint64_t would just work without problem but maybe I'm wrong

@dhood dhood Nov 4, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other lines of this PR were using uint64_t and are now being cast to int64_t which could cause overflow problems

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be cast to uint64_t though, because if the given value is negative it shouldn't be cast to an unsigned type.

I would revert this and ensure the temporary storage is large enough at the point of use, as in the lines referred to @dhood: https://github.com/ros2/rcl/pull/86/files#diff-eebe14c889bc8ee26a92052b7ae5ae08L69

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sound good, thanks for the feedback @dhood @wjwwood.
Reverting


#define RCL_NS_TO_S(nanoseconds) (nanoseconds / (1000 * 1000 * 1000))
#define RCL_NS_TO_MS(nanoseconds) (nanoseconds / (1000 * 1000))
Expand Down
4 changes: 2 additions & 2 deletions rcl/src/rcl/time_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ rcl_system_time_now(rcl_time_point_value_t * now)
RCL_SET_ERROR_MSG("unexpected negative time");
return RCL_RET_ERROR;
}
*now = RCL_S_TO_NS((uint64_t)timespec_now.tv_sec) + timespec_now.tv_nsec;
*now = RCL_S_TO_NS(timespec_now.tv_sec) + timespec_now.tv_nsec;
return RCL_RET_OK;
}

Expand Down Expand Up @@ -97,7 +97,7 @@ rcl_steady_time_now(rcl_time_point_value_t * now)
RCL_SET_ERROR_MSG("unexpected negative time");
return RCL_RET_ERROR;
}
*now = RCL_S_TO_NS((uint64_t)timespec_now.tv_sec) + timespec_now.tv_nsec;
*now = RCL_S_TO_NS(timespec_now.tv_sec) + timespec_now.tv_nsec;
return RCL_RET_OK;
}

Expand Down