From 056f37f352a354f66734facbb97797c01c4694e6 Mon Sep 17 00:00:00 2001 From: Gudmundur Adalsteinsson Date: Tue, 31 Aug 2021 18:20:02 +0000 Subject: [PATCH] Problem: fast vector resize bug Solution: init correct vector size and copy previous data into it --- src/polling_util.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/polling_util.hpp b/src/polling_util.hpp index f0ec420d..3adcdee6 100644 --- a/src/polling_util.hpp +++ b/src/polling_util.hpp @@ -76,12 +76,13 @@ template 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; + } else if (nitems_ > S) { + _dynamic_buf = new (std::nothrow) std::vector (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); } }