From eb4aaaed9f31ab4becc375d944ef5b976cf91ae2 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 19 Feb 2022 16:42:21 -0600 Subject: [PATCH] [ox/std] Fix Vector::expandCap to deallocate the correct amount of memory (synced from 4e2d7ea9dde64ec5f844172a27d7d679e7b044b3) --- src/ox/std/vector.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ox/std/vector.hpp b/src/ox/std/vector.hpp index 6ab8005ec..a9317889f 100644 --- a/src/ox/std/vector.hpp +++ b/src/ox/std/vector.hpp @@ -633,7 +633,8 @@ constexpr Error Vector::unordered_erase(std::size_t pos) { template constexpr void Vector::expandCap(std::size_t cap) { - auto oldItems = m_items; + const auto oldItems = m_items; + const auto oldCap = m_cap; m_cap = cap; this->allocate(&m_items, cap); if (oldItems) { // move over old items @@ -641,7 +642,7 @@ constexpr void Vector::expandCap(std::size_t cap) { for (std::size_t i = 0; i < itRange; ++i) { new (&m_items[i]) T(std::move(oldItems[i])); } - this->deallocate(oldItems, m_cap); + this->deallocate(oldItems, oldCap); } }