Problem: fast vector resize bug

Solution: init correct vector size and copy previous data into it
This commit is contained in:
Gudmundur Adalsteinsson 2021-08-31 18:20:02 +00:00 committed by Luca Boccassi
parent 80fef55955
commit 056f37f352

View File

@ -76,12 +76,13 @@ template <typename T, size_t S> class resizable_fast_vector_t
void resize (const size_t nitems_)
{
if (_dynamic_buf)
if (_dynamic_buf) {
_dynamic_buf->resize (nitems_);
if (nitems_ > S) {
_dynamic_buf = new (std::nothrow) std::vector<T>;
} else if (nitems_ > S) {
_dynamic_buf = new (std::nothrow) std::vector<T> (nitems_);
// TODO since this function is called by a client, we could return errno == ENOMEM here
alloc_assert (_dynamic_buf);
memcpy(&(*_dynamic_buf)[0], _static_buf, sizeof _static_buf);
}
}