Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rostime overflow bugs #61

Merged
merged 2 commits into from
Jul 21, 2017
Merged

Rostime overflow bugs #61

merged 2 commits into from
Jul 21, 2017

Conversation

dirk-thomas
Copy link
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
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

@@ -52,26 +52,30 @@ namespace ros {
template<class T>
T& DurationBase<T>::fromSec(double d)
{
sec = (int32_t)floor(d);
int64_t sec64 = (int64_t)floor(d);
if (sec64 < INT_MIN || sec64 > INT_MAX)
Copy link
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
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
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
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");

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
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