Skip to content

cast timing at macro expansion - #86

Merged
mikaelarguedas merged 1 commit into
masterfrom
cast_timing
Nov 4, 2016
Merged

mikaelarguedas merged 1 commit into
masterfrom
cast_timing

Conversation

@mikaelarguedas

Copy link
Copy Markdown
Member

Without a cast at macro expansion we get the following warning as soon as we want to wait for more that 2 seconds

warning: integer overflow in expression [-Woverflow]
 #define RCL_S_TO_NS(seconds) (seconds * (1000 * 1000 * 1000))

@mikaelarguedas mikaelarguedas added the in review Waiting for review (Kanban column) label Nov 4, 2016
@mikaelarguedas mikaelarguedas self-assigned this Nov 4, 2016
@mikaelarguedas
mikaelarguedas merged commit 5fe6c52 into master Nov 4, 2016
@mikaelarguedas
mikaelarguedas deleted the cast_timing branch November 4, 2016 17:59
@mikaelarguedas mikaelarguedas removed the in review Waiting for review (Kanban column) label Nov 4, 2016
Comment thread rcl/include/rcl/time.h
#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

mikaelarguedas added a commit that referenced this pull request Nov 4, 2016
mikaelarguedas added a commit that referenced this pull request Nov 4, 2016
ivanpauno pushed a commit that referenced this pull request Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants