Skip to content

Commit

Permalink
Problem: fast vector resize bug
Browse files Browse the repository at this point in the history
Solution: init correct vector size and copy previous data into it
  • Loading branch information
gummif authored and bluca committed Sep 1, 2021
1 parent 80fef55 commit 056f37f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/polling_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 056f37f

Please sign in to comment.