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

Fix potiential nullptr dereferenced issue in demo_nodes_cpp #242

Merged
merged 2 commits into from
Jun 19, 2018

Conversation

testkit
Copy link
Contributor

@testkit testkit commented Jun 11, 2018

Need check if it's nullptr before do std::string() convert.

@rohbotics rohbotics added the in review Waiting for review (Kanban column) label Jun 11, 2018
Copy link
Member

@dhood dhood left a 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"));
. Could you update those too please?

@@ -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")) {
Copy link
Member

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) {
Copy link
Member

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");

Copy link
Member

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

@dhood dhood added in progress Actively being worked on (Kanban column) and removed in review Waiting for review (Kanban column) labels Jun 11, 2018
@testkit testkit force-pushed the Fix_nullptr_dereference_issue branch from 8553141 to ae9c989 Compare June 13, 2018 04:25
@testkit
Copy link
Contributor Author

testkit commented Jun 13, 2018

@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

@mikaelarguedas mikaelarguedas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jun 14, 2018
  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
@dhood dhood force-pushed the Fix_nullptr_dereference_issue branch from ae9c989 to 09b635b Compare June 18, 2018 19:51
Copy link
Member

@dhood dhood left a 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.

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@dhood
Copy link
Member

dhood commented Jun 19, 2018

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.

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@dhood dhood merged commit 6ef84cd into ros2:master Jun 19, 2018
@dhood dhood removed the in review Waiting for review (Kanban column) label Jun 19, 2018
@testkit
Copy link
Contributor Author

testkit commented Jun 19, 2018

@dhood , noted and thanks!

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.

None yet

4 participants