From d207b81d2818da1753a06abc0d118b727fa505d3 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Sat, 25 Feb 2017 01:06:25 -0500 Subject: [PATCH] prevector: assert successful allocation --- src/prevector.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/prevector.h b/src/prevector.h index 3e80ef5d3..ffb26576b 100644 --- a/src/prevector.h +++ b/src/prevector.h @@ -1,6 +1,7 @@ #ifndef _BITCOIN_PREVECTOR_H_ #define _BITCOIN_PREVECTOR_H_ +#include #include #include #include @@ -166,10 +167,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(realloc(_union.indirect, ((size_t)sizeof(T)) * new_capacity)); + assert(_union.indirect); _union.capacity = new_capacity; } else { char* new_indirect = static_cast(malloc(((size_t)sizeof(T)) * new_capacity)); + assert(new_indirect); T* src = direct_ptr(0); T* dst = reinterpret_cast(new_indirect); memcpy(dst, src, size() * sizeof(T));