diff --git a/src/ipc.cpp b/src/ipc.cpp index dc15588..4e96c09 100755 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -31,8 +31,8 @@ namespace { -using msg_id_t = std::uint32_t; -using acc_t = std::atomic; +using msg_id_t = std::uint32_t; +using acc_t = std::atomic; template struct msg_t; @@ -492,8 +492,8 @@ static ipc::buff_t recv(ipc::handle_t h, std::size_t tm) { if (buf != nullptr) { if (recycled) { return ipc::buff_t{buf, msg_size, [](void* pmid, std::size_t size) { - release_storage(reinterpret_cast(pmid) - 1, size); - }, reinterpret_cast(buf_id + 1)}; + release_storage(ipc::detail::horrible_cast(pmid) - 1, size); + }, ipc::detail::horrible_cast(buf_id + 1)}; } else { return ipc::buff_t{buf, msg_size}; // no recycle } diff --git a/src/libipc/platform/detail.h b/src/libipc/platform/detail.h index fbf539a..141de6e 100755 --- a/src/libipc/platform/detail.h +++ b/src/libipc/platform/detail.h @@ -111,5 +111,17 @@ constexpr const T& (min)(const T& a, const T& b) { #endif/*__cplusplus < 201703L*/ +template +auto horrible_cast(U rhs) noexcept + -> typename std::enable_if::value + && std::is_trivially_copyable::value, T>::type { + union { + T t; + U u; + } r = {}; + r.u = rhs; + return r.t; +} + } // namespace detail } // namespace ipc