From 8d0bf40037d7eae8e2258d794be176cdfb2c8a75 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 26 Feb 2022 03:02:16 -0600 Subject: [PATCH] [ox/std] Fix Vector copy assign not to assign to uninitialized memory --- deps/ox/src/ox/std/vector.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index b8d35326b..d81776b6f 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -450,7 +450,7 @@ constexpr Vector &Vector::operator=(cons m_cap = other.m_cap; this->allocate(&m_items, other.m_cap); for (std::size_t i = 0; i < m_size; i++) { - m_items[i] = other.m_items[i]; + new (&m_items[i]) T(other.m_items[i]); } } return *this; @@ -618,6 +618,7 @@ constexpr Result::template iterator<>> Vecto for (auto i = pos; i < m_size; ++i) { m_items[i] = std::move(m_items[i + 1]); } + m_items[m_size].~T(); return begin() + pos; } @@ -628,6 +629,7 @@ constexpr Error Vector::unordered_erase(std::size_t pos) { } --m_size; m_items[pos] = std::move(m_items[m_size]); + m_items[m_size].~T(); return OxError(0); } @@ -641,6 +643,7 @@ constexpr void Vector::expandCap(std::size_t cap) { const auto itRange = ox::min(cap, m_size); for (std::size_t i = 0; i < itRange; ++i) { new (&m_items[i]) T(std::move(oldItems[i])); + oldItems[i].~T(); } this->deallocate(oldItems, oldCap); }