From: Remi Gacogne Date: Fri, 11 Mar 2022 08:38:35 +0000 (+0100) Subject: Update protozero to 1.7.1 X-Git-Tag: auth-4.7.0-alpha1~73^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3eeb9480de32d1b423dc6c7bf00a37baab74a05d;p=thirdparty%2Fpdns.git Update protozero to 1.7.1 Changes: - Fixes undefined behaviour in `float` and `double` byteswap. - Add missing includes of "config.hpp". - Avoid narrowing conversion by doing an explicit `static_cast`. --- diff --git a/ext/protozero/include/protozero/buffer_string.hpp b/ext/protozero/include/protozero/buffer_string.hpp index 1f0f902a80..02e8ad25b6 100644 --- a/ext/protozero/include/protozero/buffer_string.hpp +++ b/ext/protozero/include/protozero/buffer_string.hpp @@ -18,6 +18,7 @@ documentation. */ #include "buffer_tmpl.hpp" +#include "config.hpp" #include #include @@ -56,7 +57,8 @@ struct buffer_customization { protozero_assert(from <= buffer->size()); protozero_assert(to <= buffer->size()); protozero_assert(from <= to); - buffer->erase(std::next(buffer->begin(), from), std::next(buffer->begin(), to)); + buffer->erase(std::next(buffer->begin(), static_cast(from)), + std::next(buffer->begin(), static_cast(to))); } static char* at_pos(std::string* buffer, std::size_t pos) { diff --git a/ext/protozero/include/protozero/buffer_vector.hpp b/ext/protozero/include/protozero/buffer_vector.hpp index 6a34b072e5..c163300c58 100644 --- a/ext/protozero/include/protozero/buffer_vector.hpp +++ b/ext/protozero/include/protozero/buffer_vector.hpp @@ -18,6 +18,7 @@ documentation. */ #include "buffer_tmpl.hpp" +#include "config.hpp" #include #include @@ -56,7 +57,8 @@ struct buffer_customization> { protozero_assert(from <= buffer->size()); protozero_assert(to <= buffer->size()); protozero_assert(from <= to); - buffer->erase(std::next(buffer->begin(), from), std::next(buffer->begin(), to)); + buffer->erase(std::next(buffer->begin(), static_cast(from)), + std::next(buffer->begin(), static_cast(to))); } static char* at_pos(std::vector* buffer, std::size_t pos) { diff --git a/ext/protozero/include/protozero/byteswap.hpp b/ext/protozero/include/protozero/byteswap.hpp index 799d1795d5..75cae69109 100644 --- a/ext/protozero/include/protozero/byteswap.hpp +++ b/ext/protozero/include/protozero/byteswap.hpp @@ -19,6 +19,7 @@ documentation. #include "config.hpp" #include +#include namespace protozero { namespace detail { @@ -75,14 +76,22 @@ inline void byteswap_inplace(int64_t* ptr) noexcept { /// byteswap the data pointed to by ptr in-place. inline void byteswap_inplace(float* ptr) noexcept { - auto* bptr = reinterpret_cast(ptr); - *bptr = detail::byteswap_impl(*bptr); + static_assert(sizeof(float) == 4, "Expecting four byte float"); + + uint32_t tmp = 0; + std::memcpy(&tmp, ptr, 4); + tmp = detail::byteswap_impl(tmp); // uint32 overload + std::memcpy(ptr, &tmp, 4); } /// byteswap the data pointed to by ptr in-place. inline void byteswap_inplace(double* ptr) noexcept { - auto* bptr = reinterpret_cast(ptr); - *bptr = detail::byteswap_impl(*bptr); + static_assert(sizeof(double) == 8, "Expecting eight byte double"); + + uint64_t tmp = 0; + std::memcpy(&tmp, ptr, 8); + tmp = detail::byteswap_impl(tmp); // uint64 overload + std::memcpy(ptr, &tmp, 8); } namespace detail { diff --git a/ext/protozero/include/protozero/version.hpp b/ext/protozero/include/protozero/version.hpp index 9a0e4cc9f5..fc9b92879c 100644 --- a/ext/protozero/include/protozero/version.hpp +++ b/ext/protozero/include/protozero/version.hpp @@ -23,12 +23,12 @@ documentation. #define PROTOZERO_VERSION_MINOR 7 /// The patch number -#define PROTOZERO_VERSION_PATCH 0 +#define PROTOZERO_VERSION_PATCH 1 /// The complete version number #define PROTOZERO_VERSION_CODE (PROTOZERO_VERSION_MAJOR * 10000 + PROTOZERO_VERSION_MINOR * 100 + PROTOZERO_VERSION_PATCH) /// Version number as string -#define PROTOZERO_VERSION_STRING "1.7.0" +#define PROTOZERO_VERSION_STRING "1.7.1" #endif // PROTOZERO_VERSION_HPP