From 5726630a8f9fda321b707a914b47cb8d6d81988f Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Thu, 26 Mar 2020 14:48:33 -0300 Subject: [PATCH] Address peer review comments Signed-off-by: Ivan Santiago Paunovic --- rmw_connext_shared_cpp/src/node.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rmw_connext_shared_cpp/src/node.cpp b/rmw_connext_shared_cpp/src/node.cpp index b51d58f0..87d4167f 100644 --- a/rmw_connext_shared_cpp/src/node.cpp +++ b/rmw_connext_shared_cpp/src/node.cpp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include "rcutils/filesystem.h" @@ -72,16 +73,18 @@ create_node( participant_qos.participant_name.name = DDS::String_dup(name); // since the participant name is not part of the DDS spec // the node name is also set in the user_data - size_t length = strlen(name) + strlen("name=;") + - strlen(namespace_) + strlen("namespace=;") + - strlen(context->options.security_context) + strlen("securitycontext=;") + 1; + size_t length = std::snprintf( + nullptr, + 0, + "name=%s;namespace=%s;securitycontext=%s;", + name, namespace_, context->options.security_context) + 1; bool success = participant_qos.user_data.value.length(static_cast(length)); if (!success) { RMW_SET_ERROR_MSG("failed to resize participant user_data"); return NULL; } - int written = snprintf( + int written = std::snprintf( reinterpret_cast(participant_qos.user_data.value.get_contiguous_buffer()), length, "name=%s;namespace=%s;securitycontext=%s;",