From 5d271bf0a2eb7f1c634c5cbdadfe92f1846a6ae8 Mon Sep 17 00:00:00 2001 From: Dennis Brakhane Date: Mon, 3 Nov 2025 06:31:17 +0100 Subject: [PATCH] archive: don't use undefined behaviour (#1277) unaligned stores are technically undefinied behaviour, even though they are allowed on x86. But replacing those with memcpy should result in the same code on x86 anyway, as it's optimized away by the compiler, and will not cause issues on other architectures that don't support it. --- WickedEngine/wiArchive.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/WickedEngine/wiArchive.h b/WickedEngine/wiArchive.h index 18219d211..aed3326c2 100644 --- a/WickedEngine/wiArchive.h +++ b/WickedEngine/wiArchive.h @@ -132,7 +132,8 @@ namespace wi assert(!readMode); assert(!DATA.empty()); assert(offset + sizeof(uint64_t) < DATA.size()); - *(uint64_t*)(DATA.data() + offset) = uint64_t(pos); + uint64_t posuint64 = pos; + memcpy(DATA.data() + offset, &posuint64, sizeof(uint64_t)); } // Modifies the current archive offset // It can be used in conjunction with WriteUnknownJumpPosition() and PatchUnknownJumpPosition() @@ -490,7 +491,7 @@ namespace wi data_ptr = DATA.data(); data_ptr_size = DATA.size(); } - *(T*)(DATA.data() + pos) = data; + std::memcpy(DATA.data() + pos, &data, sizeof(data)); pos = _right; } @@ -501,7 +502,7 @@ namespace wi assert(readMode); assert(data_ptr != nullptr); assert(pos < data_ptr_size); - data = *(const T*)(data_ptr + pos); + std::memcpy(&data, data_ptr + pos, sizeof(data)); pos += (size_t)(sizeof(data)); } };