Browse Source

prevector: assert successful allocation

metaverse
Cory Fields 7 years ago
committed by Jack Grigg
parent
commit
d207b81d28
No known key found for this signature in database GPG Key ID: 665DBCD284F7DAFF
  1. 6
      src/prevector.h

6
src/prevector.h

@ -1,6 +1,7 @@
#ifndef _BITCOIN_PREVECTOR_H_
#define _BITCOIN_PREVECTOR_H_
#include <assert.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
@ -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<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));

Loading…
Cancel
Save