From fcf0a9be9546f96104f4ea1a6d7a2b3a60b1b2ba Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 19 May 2023 21:30:51 -0500 Subject: [PATCH] [ox] Fix for a broken new memory safety check in GCC13 --- deps/ox/src/ox/std/vector.hpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index b03a9c99..a00a3073 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -26,6 +26,8 @@ namespace detail { template struct VectorAllocator { + static_assert(sizeof(AllocAlias) == sizeof(T)); + static_assert(alignof(AllocAlias) == alignof(T)); private: ox::Array, Size> m_data = {}; Allocator m_allocator; @@ -46,11 +48,11 @@ struct VectorAllocator { constexpr void moveConstructItemsFrom(T **items, VectorAllocator *src, const std::size_t count, const std::size_t cap) noexcept { // this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM, // try removing it later - if (cap <= Size && count <= Size) { - const auto dstItems = reinterpret_cast(m_data.data()); - const auto srcItems = reinterpret_cast(src->m_data.data()); + if (cap <= m_data.size() && count <= m_data.size()) { for (auto i = 0u; i < count; ++i) { - std::construct_at(&dstItems[i], std::move(srcItems[i])); + const auto dstItem = reinterpret_cast(&m_data[i]); + const auto srcItem = reinterpret_cast(&src->m_data[i]); + std::construct_at(dstItem, std::move(*srcItem)); } *items = reinterpret_cast(m_data.data()); } @@ -59,11 +61,11 @@ struct VectorAllocator { constexpr void moveItemsFrom(T **items, VectorAllocator *src, const std::size_t count, const std::size_t cap) noexcept { // this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM, // try removing it later - if (cap <= Size && count <= Size) { - const auto dstItems = reinterpret_cast(m_data.data()); - const auto srcItems = reinterpret_cast(src->m_data.data()); + if (cap <= m_data.size() && count <= m_data.size()) { for (std::size_t i = 0; i < count; ++i) { - dstItems[i] = std::move(srcItems[i]); + const auto dstItem = reinterpret_cast(&m_data[i]); + const auto srcItem = reinterpret_cast(&src->m_data[i]); + *dstItem = std::move(*srcItem); } *items = reinterpret_cast(m_data.data()); }