Skip to content

Commit

Permalink
Replaced strncpy with memcpy (ros2#684)
Browse files Browse the repository at this point in the history
* Replaced strncpy with memcpy

Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
Signed-off-by: Jacob Hassold <jhassold@dcscorp.com>
  • Loading branch information
ivanpauno authored and Jacob Hassold committed Apr 15, 2019
1 parent d2686af commit 4d76d03
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions rclcpp/include/rclcpp/intra_process_manager_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <memory>
#include <mutex>
#include <set>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <utility>
Expand Down Expand Up @@ -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<typename T>
using RebindAlloc = typename std::allocator_traits<Allocator>::template rebind_alloc<T>;
Expand All @@ -301,7 +314,7 @@ class IntraProcessManagerImpl : public IntraProcessManagerImplBase
using IDTopicMap = std::map<
FixedSizeString,
AllocSet,
std::less<FixedSizeString>,
strcmp_wrapper,
RebindAlloc<std::pair<const FixedSizeString, AllocSet>>>;

SubscriptionMap subscriptions_;
Expand Down

0 comments on commit 4d76d03

Please sign in to comment.