Skip to content

Commit

Permalink
fix std::string&& to zenoh::Bytes conversion to use proper string len…
Browse files Browse the repository at this point in the history
…gth instead of null-terminator (#368)

* merge from connoranderson:connor/fix_str_tmp_conversion

* update test
  • Loading branch information
DenisBiryukov91 authored Jan 15, 2025
1 parent e5dad97 commit 920ae56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/zenoh/api/bytes.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Bytes : public Owned<::z_owned_bytes_t> {
using Dval = std::remove_reference_t<D>;
using DroppableType = typename detail::closures::Droppable<Dval>;
auto drop = DroppableType::into_context(std::forward<D>(d));
::z_bytes_from_str(interop::as_owned_c_ptr(*this), const_cast<char*>(ptr->c_str()),
::z_bytes_from_buf(interop::as_owned_c_ptr(*this), reinterpret_cast<uint8_t*>(ptr->data()), ptr->size(),
detail::closures::_zenoh_drop_with_context, drop);
}

Expand Down
5 changes: 5 additions & 0 deletions tests/universal/bytes.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ void from_into() {
std::vector<uint8_t> v = {1, 2, 4, 5, 6, 7, 8, 9, 10};
std::vector<uint8_t> v2 = v;
std::string s = "abcdefg";
// add a couple of null terminators to ensure that they are also moved into payload
s.push_back('\0');
s.push_back('h');
s.push_back('\0');
s.push_back('i');
std::string s2 = s;

Bytes bv(v), bs(s), bv2(std::move(v2)), bs2(std::move(s2));
Expand Down

0 comments on commit 920ae56

Please sign in to comment.