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

Address clang static analysis issues #865

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rcl/src/rcl/publisher.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ rcl_publisher_init(
&publisher->impl->actual_qos);
if (RMW_RET_OK != rmw_ret) {
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
ret = RCL_RET_ERROR;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The analysis flagged this assignment as unused, since fail_ret is used instead.

goto fail;
}
publisher->impl->actual_qos.avoid_ros_namespace_conventions =
Expand Down
2 changes: 2 additions & 0 deletions rcl/src/rcl/remap.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ rcl_remap_node_name(
RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_BAD_ALLOC);
RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_ERROR);

RCL_CHECK_ARGUMENT_FOR_NULL(node_name, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ALLOCATOR_WITH_MSG(&allocator, "allocator is invalid", return RCL_RET_INVALID_ARGUMENT);
return rcl_remap_name(
local_arguments, global_arguments, RCL_NODENAME_REMAP, NULL, node_name, NULL, NULL,
Expand All @@ -317,6 +318,7 @@ rcl_remap_node_namespace(
RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_BAD_ALLOC);
RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_ERROR);

RCL_CHECK_ARGUMENT_FOR_NULL(node_name, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ALLOCATOR_WITH_MSG(&allocator, "allocator is invalid", return RCL_RET_INVALID_ARGUMENT);
return rcl_remap_name(
local_arguments, global_arguments, RCL_NAMESPACE_REMAP, NULL, node_name, NULL, NULL,
Expand Down
1 change: 0 additions & 1 deletion rcl/src/rcl/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ rcl_subscription_init(
&subscription->impl->actual_qos);
if (RMW_RET_OK != rmw_ret) {
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
ret = RCL_RET_ERROR;
goto fail;
}
subscription->impl->actual_qos.avoid_ros_namespace_conventions =
Expand Down
12 changes: 8 additions & 4 deletions rcl/test/rcl/test_arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,12 @@ TEST_F(CLASSNAME(TestArgumentsFixture, RMW_IMPLEMENTATION), test_param_argument_
ASSERT_TRUE(NULL != param_value->bool_array_value);
ASSERT_TRUE(NULL != param_value->bool_array_value->values);
ASSERT_EQ(3U, param_value->bool_array_value->size);
EXPECT_TRUE(param_value->bool_array_value->values[0]);
EXPECT_FALSE(param_value->bool_array_value->values[1]);
EXPECT_FALSE(param_value->bool_array_value->values[2]);
bool bool_value = param_value->bool_array_value->values[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Analysis complains about forming a reference to a nullptr here and below, which is actually impossible. I'm not sure why it only does it with bool arrays.

EXPECT_TRUE(bool_value);
bool_value = param_value->bool_array_value->values[1];
EXPECT_FALSE(bool_value);
bool_value = param_value->bool_array_value->values[2];
EXPECT_FALSE(bool_value);
}

TEST_F(CLASSNAME(TestArgumentsFixture, RMW_IMPLEMENTATION), test_param_arguments_copy) {
Expand Down Expand Up @@ -1135,7 +1138,8 @@ TEST_F(CLASSNAME(TestArgumentsFixture, RMW_IMPLEMENTATION), test_param_overrides
param_value = rcl_yaml_node_struct_get("/**", "some.bool_param", params);
ASSERT_TRUE(NULL != param_value);
ASSERT_TRUE(NULL != param_value->bool_value);
EXPECT_FALSE(*(param_value->bool_value));
bool bool_value = *param_value->bool_value;
EXPECT_FALSE(bool_value);

param_value = rcl_yaml_node_struct_get("some_node", "int_param", params);
ASSERT_TRUE(NULL != param_value);
Expand Down