From 6fc677ccc16a18a8106681bb9aeb86feff459fb8 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sun, 30 Aug 2009 16:29:00 -0300 Subject: [PATCH] Make calloc() handle null as a malloc() result --- gc/gc.d | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gc/gc.d b/gc/gc.d index a7c8f59..f0471de 100644 --- a/gc/gc.d +++ b/gc/gc.d @@ -559,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; -- 2.43.0