From 7c52fde1f8f62a9201236dbe64d6d56cb979079d Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Sat, 17 Jan 2026 00:15:59 +0000 Subject: [PATCH] fix: crash on writing float44 type due to misaligned memory * the compiler in release builds optimizes to use movaps * this opcode requires memory alignment to 16 byte * the written memory buffer may be misaligned at this position --- src/ZoneWriting/Zone/Stream/ZoneOutputStream.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ZoneWriting/Zone/Stream/ZoneOutputStream.h b/src/ZoneWriting/Zone/Stream/ZoneOutputStream.h index 0a32486e..34d9bcc7 100644 --- a/src/ZoneWriting/Zone/Stream/ZoneOutputStream.h +++ b/src/ZoneWriting/Zone/Stream/ZoneOutputStream.h @@ -34,7 +34,9 @@ public: [[nodiscard]] ZoneStreamFillWriteAccessor AtOffset(size_t offset) const; [[nodiscard]] ZoneOutputOffset Offset() const; - template void Fill(const T& value, const size_t offset) const + template + requires(sizeof(T) <= sizeof(uintptr_t)) + void Fill(const T& value, const size_t offset) const { assert(m_block_buffer); assert(offset + sizeof(T) <= m_buffer_size); @@ -42,6 +44,16 @@ public: *reinterpret_cast(static_cast(m_block_buffer) + offset) = value; } + template + requires(sizeof(T) > sizeof(uintptr_t)) + void Fill(const T& value, const size_t offset) const + { + assert(m_block_buffer); + assert(offset + sizeof(T) <= m_buffer_size); + + std::memcpy(static_cast(m_block_buffer) + offset, &value, sizeof(T)); + } + template void FillArray(T (&value)[S], const size_t offset) const { assert(m_block_buffer);