From e90d6da01b3b6e7dca03c905d6ec33147dff3c96 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 5 Mar 2022 11:37:07 -0600 Subject: [PATCH] [ox/std] Fix problem with calling Vector::insert on end of list --- deps/ox/src/ox/std/vector.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index d81776b6..a74f6b90 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -571,10 +571,14 @@ constexpr void Vector::insert(std::size_t pos, const T &val) if (m_size == m_cap) { expandCap(m_cap ? m_cap * 2 : initialSize); } - for (auto i = m_size; i > pos; --i) { - new (&m_items[i]) T(std::move(m_items[i - 1])); + if (pos < m_size) { + for (auto i = m_size; i > pos; --i) { + new(&m_items[i]) T(std::move(m_items[i - 1])); + } + m_items[pos] = val; + } else { + new(&m_items[pos]) T(val); } - m_items[pos] = val; ++m_size; }