You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by ie...@apache.org on 2026/05/06 15:55:06 UTC
(avro) 17/17: Fix misaligned pointer use in BufferDetail.hh and BufferReader.hh (#3740)
This is an automated email from the ASF dual-hosted git repository.
iemejia pushed a commit to branch branch-1.12
in repository https://gitbox.apache.org/repos/asf/avro.git
commit 0748ec16aa129d98ddddfc4f809655e577c2d53e
Author: Andrew Pilloud <59...@users.noreply.github.com>
AuthorDate: Tue May 5 11:16:56 2026 -0700
Fix misaligned pointer use in BufferDetail.hh and BufferReader.hh (#3740)
---
lang/c++/include/avro/buffer/BufferReader.hh | 3 ++-
lang/c++/include/avro/buffer/detail/BufferDetail.hh | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/lang/c++/include/avro/buffer/BufferReader.hh b/lang/c++/include/avro/buffer/BufferReader.hh
index 39b23fa708..a08dc25120 100644
--- a/lang/c++/include/avro/buffer/BufferReader.hh
+++ b/lang/c++/include/avro/buffer/BufferReader.hh
@@ -20,6 +20,7 @@
#define avro_BufferReader_hh__
#include "Buffer.hh"
+#include <cstring>
#include <type_traits>
#ifdef min
@@ -233,7 +234,7 @@ private:
}
if (sizeof(T) <= chunkRemaining()) {
- val = *(reinterpret_cast<const T *>(addr()));
+ memcpy(&val, addr(), sizeof(T));
incrementChunk(sizeof(T));
} else {
read(reinterpret_cast<data_type *>(&val), sizeof(T));
diff --git a/lang/c++/include/avro/buffer/detail/BufferDetail.hh b/lang/c++/include/avro/buffer/detail/BufferDetail.hh
index 56e86c8a22..0e746ab721 100644
--- a/lang/c++/include/avro/buffer/detail/BufferDetail.hh
+++ b/lang/c++/include/avro/buffer/detail/BufferDetail.hh
@@ -23,6 +23,7 @@
#include <boost/asio/buffer.hpp>
#endif
#include <cassert>
+#include <cstring>
#include <deque>
#include <exception>
#include <functional>
@@ -327,7 +328,7 @@ public:
if (freeSpace_ && (sizeof(T) <= writeChunks_.front().freeSize())) {
// fast path, there's enough room in the writeable chunk to just
// straight out copy it
- *(reinterpret_cast<T *>(writeChunks_.front().tellWritePos())) = val;
+ memcpy(writeChunks_.front().tellWritePos(), &val, sizeof(T));
postWrite(sizeof(T));
} else {
// need to fixup chunks first, so use the regular memcpy