Skip to content

Commit d4ee7ba

Browse files
committed
prevector: assert successful allocation
1 parent c5f008a commit d4ee7ba

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/prevector.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef _BITCOIN_PREVECTOR_H_
66
#define _BITCOIN_PREVECTOR_H_
77

8+
#include <assert.h>
89
#include <stdlib.h>
910
#include <stdint.h>
1011
#include <string.h>
@@ -170,10 +171,15 @@ class prevector {
170171
}
171172
} else {
172173
if (!is_direct()) {
174+
/* FIXME: Because malloc/realloc here won't call new_handler if allocation fails, assert
175+
success. These should instead use an allocator or new/delete so that handlers
176+
are called as necessary, but performance would be slightly degraded by doing so. */
173177
_union.indirect = static_cast<char*>(realloc(_union.indirect, ((size_t)sizeof(T)) * new_capacity));
178+
assert(_union.indirect);
174179
_union.capacity = new_capacity;
175180
} else {
176181
char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity));
182+
assert(new_indirect);
177183
T* src = direct_ptr(0);
178184
T* dst = reinterpret_cast<T*>(new_indirect);
179185
memcpy(dst, src, size() * sizeof(T));

0 commit comments

Comments
 (0)