[ox/std] Fix Vector copy assign not to assign to uninitialized memory
This commit is contained in:
parent
21883a046e
commit
8d0bf40037
5
deps/ox/src/ox/std/vector.hpp
vendored
5
deps/ox/src/ox/std/vector.hpp
vendored
@ -450,7 +450,7 @@ constexpr Vector<T, SmallVectorSize> &Vector<T, SmallVectorSize>::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<typename Vector<T, SmallVectorSize>::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<T, SmallVectorSize>::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<T, SmallVectorSize>::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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user