0xffff-one / 0xffff-lib

0xffff-lib, a low level core library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when reserve a large chunk in vector.h

ToverPomelo opened this issue · comments

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];