From c99b60186df176f849db70a041ce6aab4d0ab03d Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 31 Mar 2020 21:42:47 -0500 Subject: [PATCH] [ox/std] Fix Vector::expandCap not to delete old array an not new one --- deps/ox/src/ox/std/vector.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index ab45828f..cfb6c487 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -219,10 +219,11 @@ bool Vector::contains(T v) const noexcept { template void Vector::insert(std::size_t pos, const T &val) noexcept { + // TODO: insert should ideally have its own expandCap if (m_size == m_cap) { expandCap(m_cap ? m_cap * 2 : 100); } - for (auto i = m_size; i > pos; i--) { + for (auto i = m_size; i > pos; --i) { m_items[i] = m_items[i - 1]; } m_items[pos] = val; @@ -280,7 +281,7 @@ void Vector::expandCap(std::size_t cap) noexcept { for (std::size_t i = itRange; i < m_cap; i++) { new (&m_items[i]) T; } - delete[] reinterpret_cast*>(m_items); + delete[] reinterpret_cast*>(oldItems); } }