-
Notifications
You must be signed in to change notification settings - Fork 329
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 potiential nullptr dereferenced issue in demo_nodes_cpp #242
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.
Thanks for the PR, @testkit. The comments that I've written apply to all of the files that have been changed, but also there are some files where the usage has not been updated e.g.
topic = std::string(rcutils_cli_get_option(argv, argv + argc, "-t")); |
@@ -65,9 +65,15 @@ int main(int argc, char ** argv) | |||
} | |||
|
|||
auto topic = std::string("add_two_ints"); | |||
|
|||
if (rcutils_cli_option_exist(argv, argv + argc, "-s")) { |
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.
we might as well remove this check now that we do not assume that rcutils_cli_get_option
will return a valid string.
topic = std::string(rcutils_cli_get_option(argv, argv + argc, "-s")); | ||
char * cli_option = rcutils_cli_get_option(argv, argv + argc, "-s"); | ||
|
||
if (NULL != cli_option) { |
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.
please use nullptr
instead of NULL
in C++
if (rcutils_cli_option_exist(argv, argv + argc, "-s")) { | ||
topic = std::string(rcutils_cli_get_option(argv, argv + argc, "-s")); | ||
char * cli_option = rcutils_cli_get_option(argv, argv + argc, "-s"); | ||
|
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.
please remove the blank space between these lines as they are directly related
8553141
to
ae9c989
Compare
@dhood, thanks for your review. PR updated as below: |
Edit based on comments about nullptr, blank space, redundent rcutils_cli_option_exist() calling. Fix the similar bug in topics/listener.cpp, topics/talker.cpp
ae9c989
to
09b635b
Compare
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.
Thanks @testkit. I rebased your branch.
I fixed the style errors. @testkit in the future please be sure to run tests for your code changes because we also have tests that check that the code complies with our style guidelines. |
@dhood , noted and thanks! |
Need check if it's nullptr before do std::string() convert.