aboutsummaryrefslogtreecommitdiff
path: root/src/prevector.h
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2017-02-25 01:06:25 -0500
committerCory Fields <cory-nospam-@coryfields.com>2017-02-27 14:52:15 -0500
commitd4ee7baef729da5e18b5e5c3d6ddb5b97df8d4e4 (patch)
treec54a3a0ef3cd5209ca34ff51d4ea57571a37133f /src/prevector.h
parentc5f008a4166bae4350881a74fc04a87d7a5c4ed5 (diff)
downloadbitcoin-d4ee7baef729da5e18b5e5c3d6ddb5b97df8d4e4.tar.xz
prevector: assert successful allocation
Diffstat (limited to 'src/prevector.h')
-rw-r--r--src/prevector.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/prevector.h b/src/prevector.h
index 6b2f578f5c..cba2e30057 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -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));