Merge pull request #991 from nogitsune-youkai/vectorFix

Fix exception safety in util::stack_vector::push_back
This commit is contained in:
MihailRis 2026-09-26 22:32:35 +03:00 • committed by GitHub
commit bac0d43fd7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -48,21 +48,25 @@ namespace util {
}
void push_back(const T& value) {
if (size_ < capacity) {
auto data = reinterpret_cast<char*>(data_.ptr() + (size_++));
new (data) T(value);
} else {
if (size_ >= capacity) {
throw std::overflow_error("stack vector capacity exceeded");
}
void* p = data_.data + size_ * sizeof(T);
::new (p) T(value);
++size_;
}
void push_back(T&& value) {
if (size_ < capacity) {
auto data = reinterpret_cast<char*>(data_.ptr() + (size_++));
new (data) T(std::move(value));
} else {
if (size_ >= capacity) {
throw std::overflow_error("stack vector capacity exceeded");
}
void* p = data_.data + size_ * sizeof(T);
::new (p) T(std::move(value));
++size_;
}
void pop_back() {