From af9ae4a61c24ba207f3db6a32c41e0e52cb29cb9 Mon Sep 17 00:00:00 2001 From: ivanpauno Date: Fri, 5 Apr 2019 16:11:01 -0300 Subject: [PATCH] Replaced strncpy with memcpy (#684) * Replaced strncpy with memcpy Signed-off-by: ivanpauno --- .../rclcpp/intra_process_manager_impl.hpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rclcpp/include/rclcpp/intra_process_manager_impl.hpp b/rclcpp/include/rclcpp/intra_process_manager_impl.hpp index 863fa4e..89784c6 100644 --- a/rclcpp/include/rclcpp/intra_process_manager_impl.hpp +++ b/rclcpp/include/rclcpp/intra_process_manager_impl.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -283,9 +284,21 @@ private: fixed_size_string(const char * str) const { FixedSizeString ret; - std::strncpy(ret.data(), str, ret.size()); + size_t size = std::strlen(str) + 1; + if (size > ret.size()) { + throw std::runtime_error("failed to copy topic name"); + } + std::memcpy(ret.data(), str, size); return ret; } + struct strcmp_wrapper + { + bool + operator()(const FixedSizeString lhs, const FixedSizeString rhs) const + { + return std::strcmp(lhs.data(), rhs.data()) < 0; + } + }; template using RebindAlloc = typename std::allocator_traits::template rebind_alloc; @@ -301,7 +314,7 @@ private: using IDTopicMap = std::map< FixedSizeString, AllocSet, - std::less, + strcmp_wrapper, RebindAlloc>>; SubscriptionMap subscriptions_;