Skip to content

Commit b76066e

Browse files
committed
Fix misaligned pointer use in BufferDetail.hh and BufferReader.hh
1 parent 79017ee commit b76066e

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lang/c++/include/avro/buffer/BufferReader.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define avro_BufferReader_hh__
2121

2222
#include "Buffer.hh"
23+
#include <cstring>
2324
#include <type_traits>
2425

2526
#ifdef min
@@ -233,7 +234,7 @@ private:
233234
}
234235

235236
if (sizeof(T) <= chunkRemaining()) {
236-
val = *(reinterpret_cast<const T *>(addr()));
237+
memcpy(&val, addr(), sizeof(T));
237238
incrementChunk(sizeof(T));
238239
} else {
239240
read(reinterpret_cast<data_type *>(&val), sizeof(T));

lang/c++/include/avro/buffer/detail/BufferDetail.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define avro_BufferDetail_hh__
2121

2222
#include <cassert>
23+
#include <cstring>
2324
#include <deque>
2425
#include <exception>
2526
#include <functional>
@@ -320,7 +321,7 @@ public:
320321
if (freeSpace_ && (sizeof(T) <= writeChunks_.front().freeSize())) {
321322
// fast path, there's enough room in the writeable chunk to just
322323
// straight out copy it
323-
*(reinterpret_cast<T *>(writeChunks_.front().tellWritePos())) = val;
324+
memcpy(writeChunks_.front().tellWritePos(), &val, sizeof(T));
324325
postWrite(sizeof(T));
325326
} else {
326327
// need to fixup chunks first, so use the regular memcpy

0 commit comments

Comments
 (0)