-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,7 +151,10 @@ namespace ros | |
|
||
double toSec() const { return (double)sec + 1e-9*(double)nsec; }; | ||
T& fromSec(double t) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Consider changing this to: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for pointing it out. Fixed in f824e46. |
||
sec = (int32_t)sec64; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely. Thank you for catching this. Too much copy-n-paste between |
||
nsec = (uint32_t)boost::math::round((t-sec) * 1e9); | ||
// avoid rounding errors | ||
sec += (nsec / 1000000000ul); | ||
|
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
andINT32_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.