diff --git a/rclcpp/include/rclcpp/intra_process_manager_impl.hpp b/rclcpp/include/rclcpp/intra_process_manager_impl.hpp index 863fa4ed6c..89784c63d1 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 @@ class IntraProcessManagerImpl : public IntraProcessManagerImplBase 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 @@ class IntraProcessManagerImpl : public IntraProcessManagerImplBase using IDTopicMap = std::map< FixedSizeString, AllocSet, - std::less, + strcmp_wrapper, RebindAlloc>>; SubscriptionMap subscriptions_;