]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Update protozero to 1.7.1
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 11 Mar 2022 08:38:35 +0000 (09:38 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 11 Jan 2022 08:38:35 +0000 (09:38 +0100)
Changes:
- Fixes undefined behaviour in `float` and `double` byteswap.
- Add missing includes of "config.hpp".
- Avoid narrowing conversion by doing an explicit `static_cast`.

ext/protozero/include/protozero/buffer_string.hpp
ext/protozero/include/protozero/buffer_vector.hpp
ext/protozero/include/protozero/byteswap.hpp
ext/protozero/include/protozero/version.hpp

index 1f0f902a800b325ce7bc826d0602d74d6568dcf9..02e8ad25b6e63c888736df398dd62bd1b6ac893d 100644 (file)
@@ -18,6 +18,7 @@ documentation.
  */
 
 #include "buffer_tmpl.hpp"
+#include "config.hpp"
 
 #include <cstddef>
 #include <iterator>
@@ -56,7 +57,8 @@ struct buffer_customization<std::string> {
         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<std::string::iterator::difference_type>(from)),
+                      std::next(buffer->begin(), static_cast<std::string::iterator::difference_type>(to)));
     }
 
     static char* at_pos(std::string* buffer, std::size_t pos) {
index 6a34b072e5463247e297c55607f2f9a9ab436ee4..c163300c58ac8634ebe660849df39c84c5a09c05 100644 (file)
@@ -18,6 +18,7 @@ documentation.
  */
 
 #include "buffer_tmpl.hpp"
+#include "config.hpp"
 
 #include <cstddef>
 #include <iterator>
@@ -56,7 +57,8 @@ struct buffer_customization<std::vector<char>> {
         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<std::string::iterator::difference_type>(from)),
+                      std::next(buffer->begin(), static_cast<std::string::iterator::difference_type>(to)));
     }
 
     static char* at_pos(std::vector<char>* buffer, std::size_t pos) {
index 799d1795d57805e7af86d441fbe1a84e165da72f..75cae69109dbf7776c6427707fc9c4f8aa31d114 100644 (file)
@@ -19,6 +19,7 @@ documentation.
 #include "config.hpp"
 
 #include <cstdint>
+#include <cstring>
 
 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<uint32_t*>(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<uint64_t*>(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 {
index 9a0e4cc9f5b0ba6587c00bff74d3ea8f62ff10c3..fc9b92879c29e1e520f7af0c0bb4eba2e2e48831 100644 (file)
@@ -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