From 078ca54fa750713c7e79da839f47219853a83315 Mon Sep 17 00:00:00 2001 From: Connor Anderson Date: Thu, 19 Dec 2024 13:54:45 -0800 Subject: [PATCH 1/2] use `reinterpret_cast` + `z_bytes_from_buf` to preserve length --- include/zenoh/api/bytes.hxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/zenoh/api/bytes.hxx b/include/zenoh/api/bytes.hxx index 278ac6b..0219fc1 100644 --- a/include/zenoh/api/bytes.hxx +++ b/include/zenoh/api/bytes.hxx @@ -94,7 +94,9 @@ class Bytes : public Owned<::z_owned_bytes_t> { using Dval = std::remove_reference_t; using DroppableType = typename detail::closures::Droppable; auto drop = DroppableType::into_context(std::forward(d)); - ::z_bytes_from_str(interop::as_owned_c_ptr(*this), const_cast(ptr->c_str()), + ::z_bytes_from_buf(interop::as_owned_c_ptr(*this), + reinterpret_cast(ptr->data()), + ptr->size(), detail::closures::_zenoh_drop_with_context, drop); } From 83ac6757f2f27e4aa368c688280a5c119669770e Mon Sep 17 00:00:00 2001 From: Connor Anderson Date: Fri, 20 Dec 2024 10:57:59 -0800 Subject: [PATCH 2/2] clang-format --- include/zenoh/api/bytes.hxx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/zenoh/api/bytes.hxx b/include/zenoh/api/bytes.hxx index 0219fc1..d28effd 100644 --- a/include/zenoh/api/bytes.hxx +++ b/include/zenoh/api/bytes.hxx @@ -94,9 +94,7 @@ class Bytes : public Owned<::z_owned_bytes_t> { using Dval = std::remove_reference_t; using DroppableType = typename detail::closures::Droppable; auto drop = DroppableType::into_context(std::forward(d)); - ::z_bytes_from_buf(interop::as_owned_c_ptr(*this), - reinterpret_cast(ptr->data()), - ptr->size(), + ::z_bytes_from_buf(interop::as_owned_c_ptr(*this), reinterpret_cast(ptr->data()), ptr->size(), detail::closures::_zenoh_drop_with_context, drop); }