mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
Fix segfaults on allocation failure (#4)
Throw std::bad_alloc instead of returning nullptr from ue2::AlignedAllocator. Allocators for STL containers are expected never to return with an invalid pointer, and instead must throw on failure. Violating this expectation can lead to invalid pointer dereferences. Co-authored-by: johanngan <johanngan.us@gmail.com>
This commit is contained in:
parent
85019432f4
commit
9b4ba34c68
@ -76,7 +76,11 @@ public:
|
||||
|
||||
T *allocate(std::size_t size) const {
|
||||
size_t alloc_size = size * sizeof(T);
|
||||
return static_cast<T *>(aligned_malloc_internal(alloc_size, N));
|
||||
T *ptr = static_cast<T *>(aligned_malloc_internal(alloc_size, N));
|
||||
if (!ptr) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void deallocate(T *x, std::size_t) const noexcept {
|
||||
|
Loading…
x
Reference in New Issue
Block a user