Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Error when reserve a large chunk in vector.h #22

Open
ToverPomelo opened this issue Aug 26, 2019 · 0 comments
Open

Error when reserve a large chunk in vector.h #22

ToverPomelo opened this issue Aug 26, 2019 · 0 comments

Comments

@ToverPomelo
Copy link

template <typename T>
void Vec<T>::reserve(size_t additional) {
size_t new_capacity = this->len + additional;
if (this->_capacity < new_capacity) reallocate(new_capacity);
}

For example:

Vec<char> vec;
vec.reserve(100000000000000);    // reserve a large chunk,
vec.reserve(-1);                                     // or reserve a negative chunk.

I suggest adding try catch in reallocate.

T* new_buf = new T[this->_capacity];

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant