X-Git-Url: https://git.llucax.com/software/dgc/naive.git/blobdiff_plain/6720d9bcaaedb553e9476ffb064115689a97c2d1..6fc677ccc16a18a8106681bb9aeb86feff459fb8:/gc/gc.d diff --git a/gc/gc.d b/gc/gc.d index 3ee81ac..f0471de 100644 --- a/gc/gc.d +++ b/gc/gc.d @@ -533,6 +533,7 @@ public: // No luck still, allocate new memory cell = cast(Cell*) cstdlib.malloc(size + Cell.sizeof); + cell.capacity = 0; // so we can later tell it's new if (cell) goto success; @@ -558,11 +559,12 @@ public: */ void* calloc(size_t size, uint attr=0) { + if (size == 0) + return null; + void* ptr = this.malloc(size, attr); - if (ptr is null) - onOutOfMemoryError(); - else + if (ptr !is null) // in case onOutOfMemoryError didn't throw cstring.memset(ptr, 0, size); return ptr;