prevector: assert successful allocation

Github-Pull: #9856
Rebased-From: d4ee7baef7
This commit is contained in:
Cory Fields 2017-02-25 01:06:25 -05:00 committed by Wladimir J. van der Laan
parent 69832aaad5
commit 775cf54d0e
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
1 changed files with 6 additions and 0 deletions

View File

@ -5,6 +5,7 @@
#ifndef _BITCOIN_PREVECTOR_H_
#define _BITCOIN_PREVECTOR_H_
#include <assert.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
@ -170,10 +171,15 @@ private:
}
} else {
if (!is_direct()) {
/* FIXME: Because malloc/realloc here won't call new_handler if allocation fails, assert
success. These should instead use an allocator or new/delete so that handlers
are called as necessary, but performance would be slightly degraded by doing so. */
_union.indirect = static_cast<char*>(realloc(_union.indirect, ((size_t)sizeof(T)) * new_capacity));
assert(_union.indirect);
_union.capacity = new_capacity;
} else {
char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity));
assert(new_indirect);
T* src = direct_ptr(0);
T* dst = reinterpret_cast<T*>(new_indirect);
memcpy(dst, src, size() * sizeof(T));