Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deserialization segfault in bionic. #199

Merged
merged 2 commits into from
May 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,32 @@ void deserialize_field(
}
}

template<>
inline void deserialize_field<std::string>(
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<std::string *>(field);
} else if (member->array_size_ && !member->is_upper_bound_) {
deser.deserializeArray(static_cast<std::string *>(field), member->array_size_);
} else {
auto & vector = *reinterpret_cast<std::vector<std::string> *>(field);
if (call_new) {
new(&vector) std::vector<std::string>;
Copy link
Member

@mikaelarguedas mikaelarguedas May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I don't think we have a guideline for this but above you have a whitespace before the parenthesis and here there is not. We should pick one and us it in both places (personnale preference would be to have a whitespace before).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that everywhere else in the file doesn't have the space, so I'll follow that convention here. Interesting that cpplint or uncrustify didn't catch it.

}
deser >> vector;
}
}

template<typename T>
void deserialize_field(
const rosidl_typesupport_introspection_c__MessageMember * member,
Expand Down