From 4f2b8c15ae5ace615aea1bc38dc534c19d517820 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 1 May 2018 09:03:20 -0500 Subject: [PATCH 1/2] Fix deserialization segfault in bionic. --- .../rmw_fastrtps_cpp/TypeSupport_impl.hpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp index 1d263638d..a0a76c1b9 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp @@ -420,6 +420,32 @@ void deserialize_field( } } +template<> +inline void deserialize_field( + const rosidl_typesupport_introspection_cpp::MessageMember * member, + void * field, + eprosima::fastcdr::Cdr & deser, + bool call_new) +{ + if (!member->is_array_) { + if (call_new) { + // Because std::string is a complex datatype, we need to make sure that + // the memory is initialized to something reasonable before eventually + // passing it as a reference to Fast-CDR. + new (field) std::string(); + } + deser >> *static_cast(field); + } else if (member->array_size_ && !member->is_upper_bound_) { + deser.deserializeArray(static_cast(field), member->array_size_); + } else { + auto & vector = *reinterpret_cast *>(field); + if (call_new) { + new(&vector) std::vector; + } + deser >> vector; + } +} + template void deserialize_field( const rosidl_typesupport_introspection_c__MessageMember * member, From a4645891d08f760484683d306258a59e63fddcd3 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Thu, 3 May 2018 08:59:56 -0500 Subject: [PATCH 2/2] Remove Whitespace --- rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp index a0a76c1b9..b0b01a234 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp @@ -432,7 +432,7 @@ inline void deserialize_field( // Because std::string is a complex datatype, we need to make sure that // the memory is initialized to something reasonable before eventually // passing it as a reference to Fast-CDR. - new (field) std::string(); + new(field) std::string(); } deser >> *static_cast(field); } else if (member->array_size_ && !member->is_upper_bound_) {