-
Notifications
You must be signed in to change notification settings - Fork 166
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
Makes rcl_action_get_*_name() functions check for empty action names. #329
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ extern "C" | |
|
||
#include "rcl_action/names.h" | ||
|
||
#include <string.h> | ||
|
||
#include "rcl/error_handling.h" | ||
#include "rcutils/format_string.h" | ||
|
||
|
@@ -30,6 +32,10 @@ rcl_action_get_goal_service_name( | |
{ | ||
RCL_CHECK_ALLOCATOR_WITH_MSG(&allocator, "allocator is invalid", return RCL_RET_INVALID_ARGUMENT); | ||
RCL_CHECK_ARGUMENT_FOR_NULL(action_name, RCL_RET_INVALID_ARGUMENT); | ||
if (0 == strlen(action_name)) { | ||
RCL_SET_ERROR_MSG("invalid empty action name"); | ||
return RCL_RET_INVALID_ARGUMENT; | ||
} | ||
RCL_CHECK_ARGUMENT_FOR_NULL(goal_service_name, RCL_RET_INVALID_ARGUMENT); | ||
if (NULL != *goal_service_name) { | ||
RCL_SET_ERROR_MSG("writing action goal service name may leak memory"); | ||
|
@@ -51,6 +57,11 @@ rcl_action_get_cancel_service_name( | |
{ | ||
RCL_CHECK_ALLOCATOR_WITH_MSG(&allocator, "allocator is invalid", return RCL_RET_INVALID_ARGUMENT); | ||
RCL_CHECK_ARGUMENT_FOR_NULL(action_name, RCL_RET_INVALID_ARGUMENT); | ||
RCL_CHECK_ARGUMENT_FOR_NULL(action_name, RCL_RET_INVALID_ARGUMENT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate of line above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Argh, fixed in 276aed1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Argh, yeah, fixed in 276aed1. |
||
if (0 == strlen(action_name)) { | ||
RCL_SET_ERROR_MSG("invalid empty action name"); | ||
return RCL_RET_INVALID_ARGUMENT; | ||
} | ||
RCL_CHECK_ARGUMENT_FOR_NULL(cancel_service_name, RCL_RET_INVALID_ARGUMENT); | ||
if (NULL != *cancel_service_name) { | ||
RCL_SET_ERROR_MSG("writing action cancel service name may leak memory"); | ||
|
@@ -72,12 +83,15 @@ rcl_action_get_result_service_name( | |
{ | ||
RCL_CHECK_ALLOCATOR_WITH_MSG(&allocator, "allocator is invalid", return RCL_RET_INVALID_ARGUMENT); | ||
RCL_CHECK_ARGUMENT_FOR_NULL(action_name, RCL_RET_INVALID_ARGUMENT); | ||
if (0 == strlen(action_name)) { | ||
RCL_SET_ERROR_MSG("invalid empty action name"); | ||
return RCL_RET_INVALID_ARGUMENT; | ||
} | ||
RCL_CHECK_ARGUMENT_FOR_NULL(result_service_name, RCL_RET_INVALID_ARGUMENT); | ||
if (NULL != *result_service_name) { | ||
RCL_SET_ERROR_MSG("writing action result service name may leak memory"); | ||
return RCL_RET_INVALID_ARGUMENT; | ||
} | ||
|
||
*result_service_name = rcutils_format_string(allocator, "%s/_action/get_result", action_name); | ||
if (NULL == *result_service_name) { | ||
RCL_SET_ERROR_MSG("failed to allocate memory for action result service name"); | ||
|
@@ -94,6 +108,10 @@ rcl_action_get_feedback_topic_name( | |
{ | ||
RCL_CHECK_ALLOCATOR_WITH_MSG(&allocator, "allocator is invalid", return RCL_RET_INVALID_ARGUMENT); | ||
RCL_CHECK_ARGUMENT_FOR_NULL(action_name, RCL_RET_INVALID_ARGUMENT); | ||
if (0 == strlen(action_name)) { | ||
RCL_SET_ERROR_MSG("invalid empty action name"); | ||
return RCL_RET_INVALID_ARGUMENT; | ||
} | ||
RCL_CHECK_ARGUMENT_FOR_NULL(feedback_topic_name, RCL_RET_INVALID_ARGUMENT); | ||
if (NULL != *feedback_topic_name) { | ||
RCL_SET_ERROR_MSG("writing action feedback topic name may leak memory"); | ||
|
@@ -115,6 +133,10 @@ rcl_action_get_status_topic_name( | |
{ | ||
RCL_CHECK_ALLOCATOR_WITH_MSG(&allocator, "allocator is invalid", return RCL_RET_INVALID_ARGUMENT); | ||
RCL_CHECK_ARGUMENT_FOR_NULL(action_name, RCL_RET_INVALID_ARGUMENT); | ||
if (0 == strlen(action_name)) { | ||
RCL_SET_ERROR_MSG("invalid empty action name"); | ||
return RCL_RET_INVALID_ARGUMENT; | ||
} | ||
RCL_CHECK_ARGUMENT_FOR_NULL(status_topic_name, RCL_RET_INVALID_ARGUMENT); | ||
if (NULL != *status_topic_name) { | ||
RCL_SET_ERROR_MSG("writing action status topic name may leak memory"); | ||
|
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.
Suggest returning
RCL_RET_ACTION_NAME_INVALID
. Then it makes it possible for the action client/server to know if the provided name is empty (invalid) vs a null argument. Same for other functions and also update the docs to include the new return type.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.
Alright, makes sense. Done in 276aed1.