Skip to content

Rostime overflow bugs#61

Merged
dirk-thomas merged 2 commits intokinetic-develfrom
rostime_overflow_bugs
Jul 21, 2017
Merged

Rostime overflow bugs#61
dirk-thomas merged 2 commits intokinetic-develfrom
rostime_overflow_bugs

Conversation

@dirk-thomas
Copy link
Copy Markdown
Member

Replaces #58.

The first commit uses the tests proposed in #58. The second commit updates the implementation to pass the new tests. In contrast to the proposed fix in #58 the patch is smaller and imo simpler in logic.

@ros/ros_team Please review.

Copy link
Copy Markdown
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

changes lgtm

{
sec = (int32_t)floor(d);
int64_t sec64 = (int64_t)floor(d);
if (sec64 < INT_MIN || sec64 > INT_MAX)
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.

You might consider using INT32_MIN and INT32_MAX instead, reference:

http://en.cppreference.com/w/cpp/types/integer

(here and below)

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.

I agree using (U)INT32_MIN|MAX would indeed be nicer. I kept it with (U)INT_MIN|MAX for now since those are already being used within the code. I would rather not mix them and don't want to update the existing code.

@dirk-thomas dirk-thomas merged commit e005bf6 into kinetic-devel Jul 21, 2017
@dirk-thomas dirk-thomas deleted the rostime_overflow_bugs branch July 21, 2017 01:41
int64_t sec64 = (int64_t)floor(t);
if (sec64 < 0 || sec64 > UINT_MAX)
throw std::runtime_error("Duration is out of dual 32-bit range");
sec = (int32_t)sec64;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why cast to int32_t, not to uint32_t? For me, uint seems logical.

Copy link
Copy Markdown
Member Author

@dirk-thomas dirk-thomas Jul 23, 2017

Choose a reason for hiding this comment

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

Absolutely. Thank you for catching this. Too much copy-n-paste between Duration and Time. I created #63 to address it.

dirk-thomas added a commit that referenced this pull request Jul 23, 2017
dirk-thomas added a commit that referenced this pull request Jul 24, 2017
sec = (uint32_t)floor(t);
int64_t sec64 = (int64_t)floor(t);
if (sec64 < 0 || sec64 > UINT_MAX)
throw std::runtime_error("Duration is out of dual 32-bit range");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider changing this to:
"Time is out of dual unsigned 32-bit range".
Avoids ambiguity for people who are trying to debug, and it is more accurate. The ros_comm repo is currently failing the empty_timestamp_crash_check test with this exception, which is why I'm making the suggestion.

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.

Thank you for pointing it out. Fixed in f824e46.

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