From f4ca542b92e118881e473b38415935243c551eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 27 Mar 2017 16:30:20 +0200 Subject: [PATCH] Add assertions in ChunkedVector to detect failed memory allocations. --- source/eventcore/internal/utils.d | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/eventcore/internal/utils.d b/source/eventcore/internal/utils.d index db252ef..23b2952 100644 --- a/source/eventcore/internal/utils.d +++ b/source/eventcore/internal/utils.d @@ -118,6 +118,7 @@ struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) { while (l <= chunkidx) l *= 2; () @trusted { auto newptr = cast(ChunkPtr*)realloc(m_chunks.ptr, l * ChunkPtr.length); + assert(newptr !is null, "Failed to allocate chunk index!"); m_chunks = newptr[0 .. l]; } (); } @@ -125,6 +126,7 @@ struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) { while (m_chunkCount <= chunkidx) { () @trusted { auto ptr = cast(ChunkPtr)calloc(chunkSize, T.sizeof); + assert(ptr !is null, "Failed to allocate chunk!"); GC.addRange(ptr, chunkSize * T.sizeof); m_chunks[m_chunkCount++] = ptr; } ();