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..a4d5ac1a7 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp @@ -573,6 +573,12 @@ bool TypeSupport::deserializeROSmessage( deserialize_field(member, field, deser, call_new); break; case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_STRING: + // 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. + if(!member->is_array_) { + new (field) std::string(); + } deserialize_field(member, field, deser, call_new); break; case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE: