Skip to content

Commit

Permalink
prevector: assert successful allocation
Browse files Browse the repository at this point in the history
Github-Pull: #9856
Rebased-From: d4ee7ba
  • Loading branch information
theuni authored and laanwj committed Feb 28, 2017
1 parent 69832aa commit 775cf54
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/prevector.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef _BITCOIN_PREVECTOR_H_
#define _BITCOIN_PREVECTOR_H_

#include <assert.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -170,10 +171,15 @@ class prevector {
}
} 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));
Expand Down

0 comments on commit 775cf54

Please sign in to comment.