cpbuffer extract(): use integer arithmetic instead of char pointer.
authorDavin McCall <davmac@davmac.org>
Tue, 18 Sep 2018 22:31:37 +0000 (23:31 +0100)
committerDavin McCall <davmac@davmac.org>
Thu, 20 Sep 2018 08:43:18 +0000 (09:43 +0100)
The method is designed to extract data to an arbitrary type, and while
char * should probably be safe to do that with, conversion to char * is
not specified in C++ as it is in C, and compilers are becoming more
aggressive.

src/includes/cpbuffer.h

index 9471ad8829dd4ca1b46405606c19137876dce25d..832c3daad7d1b4adc2ffb2ac02f40a292ad0a12e 100644 (file)
@@ -112,7 +112,7 @@ template <int SIZE> class cpbuffer
     }
     
     // Extract bytes from the buffer. The bytes remain in the buffer.
-    void extract(char *dest, int index, int length) noexcept
+    void extract(void *dest, int index, int length) noexcept
     {
         index += cur_idx;
         if (index >= SIZE) index -= SIZE;
@@ -120,7 +120,8 @@ template <int SIZE> class cpbuffer
             // wrap-around copy
             int half = SIZE - index;
             std::memcpy(dest, buf + index, half);
-            std::memcpy(dest + half, buf, length - half);
+            std::memcpy(reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(dest) + half),
+                    buf, length - half);
         }
         else {
             std::memcpy(dest, buf + index, length);