-
Notifications
You must be signed in to change notification settings - Fork 116
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
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
fixed cast introduced in #61
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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.