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 the dereference to NULL #405

Merged
merged 5 commits into from
Jan 8, 2018
Merged

Fix the dereference to NULL #405

merged 5 commits into from
Jan 8, 2018

Conversation

gaoethan
Copy link
Contributor

@gaoethan gaoethan commented Nov 21, 2017

rmw_*_validation_result_string(validation_result) may return NULL,
and it's dereferenced by passing arg to NameValidationError, this
leads unexpected behaviors and NULL is deprecated to use in C++ now.

Signed-off-by: Ethan Gao ethan.gao@linux.intel.com

Connects to ros2/rmw#130


const char * validation_result_string = rmw_node_name_validation_result_string(
validation_result);
validation_result_string = validation_result_string ? validation_result_string : "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While using the ternary operator isn't exactly wrong, it is definitely odd to be re-assigning a variable back to itself. I'd prefer a simple if (nullptr == validation_result_string) here. Also, we should probably have a slightly different string than ""; maybe something like "Unknown error".

The same goes for the rest of the calls below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I've ever tried to make the error string specific, but when the result is valid, it also return NULL which is different from the default NULL in some sense, so it's not accurate if we treat all the NULL to "unknown error", I prefer to tweak the rmw_*validate_result_string to get it more accurate, any comments ? thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think I agree that we should ensure that the rmw_*_validation_result_string should probably never return NULL. I'll make a similar comment over in ros2/rmw#130 , but let's leave this open for now just in case we come to a different conclusion over there.

@gaoethan
Copy link
Contributor Author

please evaluate to unify the undefined case in rmw_*_validation_result_string or deal with separate code while using based on #ros2/rmw#130

@mikaelarguedas mikaelarguedas added the in review Waiting for review (Kanban column) label Nov 24, 2017
} else {
using rclcpp::exceptions::InvalidTopicNameError;
throw InvalidTopicNameError(name.c_str(), validation_message, invalid_index);
eles {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo ?
This also need to be on the same line as the above closing curly bracket to pass the linters

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this else is not necessary as if we enter the if we throw an error so the previous code can be kept

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's a typo (my bad), actually the else got changed to not on the same line after I ran ament_uncrusitify --reformat, let me check.

why I add the else is because it will return NULL if validation_result is RCL_TOPIC_NAME_VALID, it will be problematic for InvalidTopicNameError and InvalidServiceNameError

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why I add the else is because it will return NULL if validation_result is RCL_TOPIC_NAME_VALID, it will be problematic for InvalidTopicNameError and InvalidServiceNameError

My understanding is that this is taken care of by the if just before

        if (validation_result == RCL_TOPIC_NAME_VALID) {
          throw std::runtime_error("topic name unexpectedly valid");
        }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaoethan This comment has not been addressed.
I think that the following snippet should be kept. If this evaluates to true the code below is unreacheable as we throw. If it doesnt we're sure we're not in the case of validation_result == RCL_TOPIC_NAME_VALID

        if (validation_result == RCL_TOPIC_NAME_VALID) {
          throw std::runtime_error("topic name unexpectedly valid");
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I have kept it, :) generally speaking, it has lower possibility to hit that and I put it in the else statement

node_name.c_str(),
rmw_node_name_validation_result_string(validation_result),
invalid_index);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if what scenario that can happen but should we do something in the else case ? (case where the rcl node name is valid but the rmw node name is not) (same everywhere below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this if is under umbrella of RCL_RET_NODE_INVALID_NAME and it's currently handling the cases of invalid rmw node name as you point :). or what you really mean the case that rcl node name is invalid but rwm node name is valid ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed that's what I meant 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikaelarguedas now it's not sure when this will happen, I throw exceptions for the case of valid rmw with invalid rcl checking to allow the user to be aware of that for further investigation.

Copy link
Member

@mikaelarguedas mikaelarguedas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except for one remaining comment this looks good to me

gaoethan and others added 5 commits December 19, 2017 17:44
rmw_*_validation_result_string(validation_result) may return NULL,
and it's dereferenced by passing arg to NameValidationError

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>
Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>
to the change of API rmw_*_validation_result_string

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>
Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>
@mikaelarguedas mikaelarguedas dismissed stale reviews from clalancette and themself December 22, 2017 03:31

lots of things changed

Copy link
Member

@mikaelarguedas mikaelarguedas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mikaelarguedas mikaelarguedas merged commit b81f55e into ros2:master Jan 8, 2018
@mikaelarguedas mikaelarguedas removed the in review Waiting for review (Kanban column) label Jan 8, 2018
@gaoethan gaoethan deleted the bugfix branch January 9, 2018 07:04
nnmm pushed a commit to ApexAI/rclcpp that referenced this pull request Jul 9, 2022
* Update after launch_testing features becoming legacy.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Migrate rcl tests to new launch_testing API.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Migrate missing rcl test to new launch_testing API.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this pull request Aug 5, 2022
…ncludes are not required (ros2#405)

Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
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

3 participants