Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Fix conversion of negative durations to messages #1188
Fix conversion of negative durations to messages #1188
Changes from 4 commits
597817d
cf6c8c3
3628064
683ac64
f9cf569
f5fed09
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
This static_cast just makes explicit what the compiler would also have done implicitly.
The check below may also not do what is expected:
strtoul()
converts the string tounsigned long
, and returnsULONG_MAX
in case of an overflow. On my machine (Linux 64-bit)unsigned long
is a 64 bit type, which is also why the implicit conversion touint32_t
triggered a compiler warning with-Wconversion
. But that also means that only values exceeding18446744073709551617
and all multiples of4294967296
minus 1 trigger the run-time exception.4294967296
is silently cast to0
,4294967297
to1
etc.Illegal values like
"foo"
would also silently be interpreted as0
without an error, becausestrtoul
simply stops parsing at the first invalid character. You would have to pass achar **
as the second argumentstr_end
instead ofNULL
and check whether it points to the end of the string (the terminating null character).The conversions should probably use C++ stringstreams or the C++11 equivalent std::stoul with an additional range check, instead of error-prone C functions. Or, if the function must be implemented in C to avoid code duplication with
rcl
, as stated in @wjwwood's comment above, the solution would be to useunsigned long
instead ofuint32_t
without a cast, check that thestr_end
actually points to the terminating null character after conversion, and to add an explicit range check before the cast to the desired output type.Apparently the issue is already discussed in ros2/rcl#689.